RSS

Monthly Archives: September 2011

SQL Server memory configuration

On the Start menu, click Run. In the Open box, type gpedit.msc.

2. The Group Policy dialog box opens.

3. On the Group Policy console, expand Computer Configuration, and then expand Windows Settings.

 4. Expand Security Settings, and then expand Local Policies.

 5. Select the User Rights Assignment folder.

6. The policies will be displayed in the details pane.

7. In the pane, double-click Lock pages in memory.

8. In the Local Security Policy Setting dialog box, click Add.

 9. In the Select Users or Groups dialog box, add an account with privileges to run sqlservr.exe.

 Finally to enable AWE:

 1. In SQL Server Management Studio, right-click a server and select Properties.

2. Click the Memory node. 3. Under Server memory options, select Use AWE to allocate memory.

 
Leave a comment

Posted by on September 30, 2011 in SQl server Administration

 

SQL Server 2008R2 Error After intall Then Make Update To Your PC

SQL Server 2008R2 Error After intall Then Make Update To Your PC

 

Introduction

 
Yesterday I install SQL  server 2008R2 in my Laptop  Then After install I make update to my pc in this update I download update for SQL Server 2008R2
This Update  Name  is

(Security Update for SQL Server 2008 R2 (KB2494088))
Then after I intall the update I make restart to my laptop then I try to connect to my instance SQL server 2008R2 I receive this Error massage

Login failed for user ‘Elmasry-PC\Elmasry’. Reason: Server is in script upgrade mode (Only administrator can connect at this time. (Microsoft SQL Server, Error: 18401)) .


 When I see this error I can’t believe my easy  Because before 5 minutes before the update my instance was worked very good so I make search on the internet  and I can fix this error

 
The Solution

 
1. Enable trace flag 902 on the instance of SQL Server 2008 R2. To do this, follow these steps:
a. Open SQL Server Configuration Manager.
b. In SQL Server Configuration Manager, click SQL Server Services.
c. Double-click the SQL Server service.
d. In the SQL Server Properties dialog box, click the Advanced tab.
e. On click the Advanced tab, locate the Startup Parameters item.
f. Add(( ;-T902 )) to the end of the existing string value, and then click OK.
2. Right-click the SQL Server service, and then click Start.
3. If the SQL Server Agent service is running, right-click the SQL Server Agent service, and then click Stop.
4. Open SQL Server Management Studio, and then connect to the instance of SQL Server 2008 R2.
5. Run the following statements:

EXEC sp_configure ‘show advanced’, 1;
RECONFIGURE;
EXEC sp_configure ‘allow updates’, 0;
RECONFIGURE;
EXEC sp_configure ‘Agent XPs’, 1;
RECONFIGURE;
GO

Note  :

In steps No 5 I receive another Error massage this Massage is ((ad hoc update to system catalogs is not supported)) So if you Receive this error try to make this step (Fix Ad Hoc) If you don’t receive this error go to step no 6

 
Fix Ad Hoc
Run This Script then Try to make the step No 5 Again
sp_configure ‘show advanced options’,1
reconfigure
go
sp_configure ‘xp_cmdshell’,1
reconfigure
go
sp_configure ‘show advanced options’,1
reconfigure with override
go
sp_configure ‘xp_cmdshell’,1
reconfigure with override
go

—Reset the “allow updates” setting to the recommended 0
sp_configure ‘allow updates’,0
reconfigure with override
go
—Reset the environment back as the test is complete
sp_configure ‘xp_cmdshell’,0
reconfigure
go
sp_configure ‘show advanced options’,0
reconfigure
go

6. In SQL Server Configuration Manager, right-click the SQL Server service, and then click Stop.
7. Remove trace flag 902 on the instance of SQL Server 2008 R2. To do this, delete((  ;-T902 )) from the string value that you updated in step 1f.
8. Right-click the SQL Server service, and then click Start.
9. Right-click the SQL Server Agent service, and then click Start.
10. In SQL Server Management Studio, reconnect to the instance of SQL Server 2008 R2.
11. In Object Explorer, expand Management, right-click Data Collection, and then click Enable Data Collection.
Note :

 You may receive the following error message when you connect to the instance of SQL Server 2008 R2 in SQL Server Management Studio:
Error: 18401
Login failed for user ‘<login name>’. Reason: Server is in script upgrade mode. Only administrator can connect at this time.


This error message indicates that SQL Server 2008 R2 is completing the installation of cumulative update package 1. If you receive this error message, wait several minutes and then connect to the instance of SQL Server 2008 R2 again.
 Best Regards

Mostafa Elmasry

 
Leave a comment

Posted by on September 25, 2011 in Errors

 

50 New Features of SQL Server 2008

Transparent Data Encryption

Enable encryption of an entire database, data files, or log files, without the need for application changes. Benefits of this include: Search encrypted data using both range and fuzzy searches, search secure data from unauthorized users, and data encryption without any required changes in existing applications

Extensible Key Management

SQL Server 2005 provides a comprehensive solution for encryption and key management. SQL Server 2008 delivers an excellent solution to this growing need by supporting third-party key management and HSM products

Auditing

Create and manage auditing via DDL, while simplifying compliance by providing more comprehensive data auditing. This enables organizations to answer common questions, such as, “What data was retrieved?”

Enhanced Database Mirroring

SQL Server 2008 builds on SQL Server 2005 by providing a more reliable platform that has enhanced database mirroring, including automatic page repair, improved performance, and enhanced supportability.

Automatic Recovery of Data Pages

SQL Server 2008 enables the principal and mirror machines to transparently recover from 823/824 types of data page errors by requesting a fresh copy of the suspect page from the mirroring partner transparently to end users and applications.

Log Stream Compression

Database mirroring requires data transmissions between the participants of the mirroring implementations. With SQL Server 2008, compression of the outgoing log stream between the participants delivers optimal performance and minimizes the network bandwidth used by database mirroring.

Resource Governor

Provide a consistent and predictable response to end users with the introduction of Resource Governor, allowing organizations to define resource limits and priorities for different workloads, which enable concurrent workloads to provide consistent performance to their end users.

Predictable Query Performance

Enable greater query performance stability and predictability by providing functionality to lock down query plans, enabling organizations to promote stable query plans across hardware server replacements, server upgrades, and production deployments.

Data Compression

Enable data to be stored more effectively, and reduce the storage requirements for your data. Data compression also provides significant performance improvements for large I/O bound workloads, like data warehousing.

Hot Add CPU

Dynamically scale a database on demand by allowing CPU resources to be added to SQL Server 2008 on supported hardware platforms without forcing any downtime on applications. Note that SQL Server already supports the ability to add memory resources online.

Policy-Based Management

Policy-Based Management is a policy-based system for managing one or more instances of SQL Server 2008. Use this with SQL Server Management Studio to create policies that manage entities on the server, such as the instance of SQL Server, databases, and other SQL Server objects

Streamlined Installation

SQL Server 2008 introduces significant improvements to the service life cycle for SQL Server through the re-engineering of the installation, setup, and configuration architecture. These improvements separate the installation of the physical bits on the hardware from the configuration of the SQL Server software, enabling organizations and software partners to provide recommended installation configurations.

Performance Data Collection

Performance tuning and troubleshooting are time-consuming tasks for the administrator. To provide actionable performance insights to administrators, SQL Server 2008 includes more extensive performance data collection, a new centralized data repository for storing performance data, and new tools for reporting and monitoring.

Language Integrated Query (LINQ)

Enable developers to issue queries against data, using a managed programming language, such as C# or VB.NET, instead of SQL statements. Enable seamless, strongly typed, set-oriented queries written in .NET languages to run against ADO.NET (LINQ to SQL), ADO.NET DataSets (LINQ to DataSets), the ADO.NET Entity Framework (LINQ to Entities), and to the Entity Data Service Mapping provider. Use the new LINQ to SQL provider that enables developers to use LINQ directly on SQL Server 2008 tables and columns.

ADO.NET Data Services

The Object Services layer of ADO.NET enables the materialization, change tracking, and persistence of data as CLR objects. Developers using the ADO.NET framework can program against a database, using CLR objects that are managed by ADO.NET. SQL Server 2008 introduces more efficient, optimized support that improves performance and simplifies development.

 DATE/TIME

SQL Server 2008 introduces new date and time data types:

  • DATE—A date-only type
  • TIME—A time-only type
  • DATETIMEOFFSET—A time-zone-aware datetime type
  • DATETIME2—A datetime type with larger fractional seconds and year range than the existing DATETIME type

The new data types enable applications to have separate data and time types while providing large data ranges or user defined precision for time values.

HIERARCHY ID

Enable database applications to model tree structures in a more efficient way than currently possible. New system type HierarchyId can store values that represent nodes in a hierarchy tree. This new type will be implemented as a CLR UDT, and will expose several efficient and useful built-in methods for creating and operating on hierarchy nodes with a flexible programming model.

FILESTREAM Data

Allow large binary data to be stored directly in an NTFS file system, while preserving an integral part of the database and maintaining transactional consistency. Enable the scale-out of large binary data traditionally managed by the database to be stored outside the database on more cost-effective storage without compromise.

Integrated Full Text Search

Integrated Full Text Search makes the transition between Text Search and relational data seamless, while enabling users to use the Text Indexes to perform high-speed text searches on large text columns.

Sparse Columns

NULL data consumes no physical space, providing a highly efficient way of managing empty data in a database. For example, Sparse Columns allows object models that typically have numerous null values to be stored in a SQL Server 2005 database without experiencing large space costs.

Large User-Defined Types

SQL Server 2008 eliminates the 8-KB limit for User-Defined Types (UDTs), allowing users to dramatically expand the size of their UDTs

Spatial Data Types

Build spatial capabilities into your applications by using the support for spatial data.

  • Implement Round Earth solutions with the geography data type. Use latitude and longitude coordinates to define areas on the Earth’s surface.
  • Implement Flat Earth solutions with the geometry data type. Store polygons, points, and lines that are associated with projected planar surfaces and naturally planar data, such as interior spaces.

Backup Compression

Keeping disk-based backups online is expensive and time-consuming. With SQL Server 2008 backup compression, less storage is required to keep backups online, and backups run significantly faster since less disk I/O is required.

Partitioned Table Parallelism

Partitions enable organizations to manage large growing tables more effectively by transparently breaking them into manageable blocks of data. SQL Server 2008 builds on the advances of partitioning in SQL Server 2005 by improving the performance on large partitioned tables.

Star Join Query Optimizations

SQL Server 2008 provides improved query performance for common data warehouse scenarios. Star Join Query optimizations reduce query response time by recognizing data warehouse join patterns.

Grouping Sets

Grouping Sets is an extension to the GROUP BY clause that lets users define multiple groupings in the same query. Grouping Sets produces a single result set that is equivalent to a UNION ALL of differently grouped rows, making aggregation querying and reporting easier and faster.

Change Data Capture

With Change Data Capture, changes are captured and placed in change tables. It captures complete content of changes, maintains cross-table consistency, and even works across schema changes. This enables organizations to integrate the latest information into the data warehouse.

MERGE SQL Statement

With the introduction of the MERGE SQL Statement, developers can more effectively handle common data warehousing scenarios, like checking whether a row exists, and then executing an insert or update.

SQL Server Integration Services (SSIS) Pipeline Improvements

Data Integration packages can now scale more effectively, making use of available resources and managing the largest enterprise-scale workloads. The new design improves the scalability of runtime into multiple processors.

SQL Server Integration Services (SSIS) Persistent Lookups

The need to perform lookups is one of the most common ETL operations. This is especially prevalent in data warehousing, where fact records need to use lookups to transform business keys to their corresponding surrogates. SSIS increases the performance of lookups to support the largest tables.

Analysis Scale and Performance

SQL Server 2008 drives broader analysis with enhanced analytical capabilities and with more complex computations and aggregations. New cube design tools help users streamline the development of the analysis infrastructure enabling them to build solutions for optimized performance.

Block Computations

Block Computations provides a significant improvement in processing performance enabling users to increase the depth of their hierarchies and complexity of the computations

Writeback

New MOLAP enabled writeback capabilities in SQL Server 2008 Analysis Services removes the need to query ROLAP partitions. This provides users with enhanced writeback scenarios from within analytical applications without sacrificing the traditional OLAP performance.

Enterprise Reporting Engine

Reports can easily be delivered throughout the organization, both internally and externally, with simplified deployment and configuration. This enables users to easily create and share reports of any size and complexity.

Internet Report Deployment

Customers and suppliers can effortlessly be reached by deploying reports over the Internet

Manage Reporting Infrastructure

Increase supportability and the ability to control server behaviour with memory management, infrastructure consolidation, and easier configuration through a centralized store and API for all configuration settings.

Report Builder Enhancements

Easily build ad-hoc and author reports with any structure through Report Designer.

Forms Authentication Support

Support for Forms authentication enables users to choose between Windows and Forms authentication.

Report Server Application Embedding

Report Server application embedding enables the URLs in reports and subscriptions to point back to front-end applications.

Microsoft Office Integration

SQL Server 2008 provides new Word rendering that enables users to consume reports directly from within Microsoft Office Word. In addition, the existing Excel renderer has been greatly enhanced to accommodate the support of features, like nested data regions, sub-reports, as well as merged cell improvements. This lets users maintain layout fidelity and improves the overall consumption of reports from Microsoft Office applications.

Predictive Analysis

SQL Server Analysis Services continues to deliver advanced data mining technologies. Better Time Series support extends forecasting capabilities. Enhanced Mining Structures deliver more flexibility to perform focused analysis through filtering as well as to deliver complete information in reports beyond the scope of the mining model. New cross-validation enables confirmation of both accuracy and stability for results that you can trust. Furthermore, the new features delivered with SQL Server 2008 Data Mining Add-ins for Office 2007 empower every user in the organization with even more actionable insight at the desktop. 

 

 

 

 
Leave a comment

Posted by on September 23, 2011 in General topics

 

List all login and user on server and on database

List All login On All Server

SELECT * FROM sys.server_principals WHERE type IN (‘S’, ‘U’, ‘G’) ORDER BY name ASC

List All User On Server

SELECT * FROM sys.database_principals WHERE type in (‘U’, ‘G’, ‘S’)

 
Leave a comment

Posted by on September 16, 2011 in General topics

 

Clear Recent SQL Server Connection List From SSMS

SQL Server 2005

1.Make sure that the “SQL Server management studio” is not opened
2.Go to “Run”
3.Type this command “%APPDATA%\Microsoft\Microsoft SQL Server\90\Tools\Shell\” and click “OK”. This will open up the folder where this list is stored.
4.Now search for the file “mru.dat” and rename this file.
5.After renaming, launch the SQL Server management studio and you will not see any of the most recently used servers in the list.

 SQL Server 2008

1.Make sure that the “SQL Server management studio” is not opened
2.Go to “Run”
3.Type this command “%APPDATA%\Microsoft\Microsoft SQL Server\100\Tools\Shell\” and click “OK”. This will open up the folder where this list is stored
4.Now search for the file “SqlStudio.bin” and delete / rename this file.
5.After deleting, launch the SQL Server management studio and you will not see any of the most recently used servers in the list.


SQL Server 2012

view this video because in 2012 it’s very easy you can clear it from the SQL Server management Studio

 
Leave a comment

Posted by on September 16, 2011 in Administration, New Feature

 

find space utilized by every database object

Following Script will help us to find space utilized by every database object, this includes number of rows and size taken by every table.

DECLARE @projected_size nvarchar(2)
SET @projected_size = NULL

declare        @db_count    bigint,
            @loop_count    bigint,
            @sqlstat    varchar(7000),
            @sqlstat2    varchar(7000),
            @sqlstat3   varchar(7000),
            @sqlstat4   varchar(7000),
            @sqlstat5   varchar(7000),
            @db_name    varchar(150)

CREATE TABLE #tablestats
(
    database_name        varchar(150),
    table_name            varchar(700),
    table_id            bigint,
    data_size            nvarchar(38),
    reserved_size        nvarchar(38),
    unused_size            nvarchar(38),
    index_size            nvarchar(38),
    primary_key_size    nvarchar(38),
    number_rows_table    bigint
)
CREATE TABLE #alltablestats
(
    database_name        varchar(150),
    table_name            varchar(700),
    table_id            bigint,
    data_size            nvarchar(15),
    reserved_size        nvarchar(15),
    unused_size            nvarchar(15),
    index_size            nvarchar(15),
    primary_key_size    nvarchar(15),
    number_rows_table    bigint
)
CREATE TABLE #tabpage
(
    database_name        varchar(150),
    table_name            varchar(700),
    table_id            bigint,
    page_size            dec(30,0),
    used_size            dec(30,0),
    index_size            dec(30,0)
)

CREATE TABLE #pkhold
(
    pk_id                bigint,
    pk_name              varchar(400),
    parent_id            bigint,
    pk_size                nvarchar(15)
)
CREATE TABLE #capacity
(
    tb_id                bigint identity,
    database_name        varchar(150),
    database_id            bigint
)

IF @projected_size  IS null or @projected_size = ‘0’
  SET @projected_size = ‘1’

SET @loop_count = 1

/*****************************************************************************
***get database names on server                                            ***
******************************************************************************/
INSERT INTO #capacity(database_name,database_id)
SELECT DISTINCT name,dbid
FROM master..sysdatabases

SELECT @db_count = count(*)
FROM #capacity

WHILE @loop_count <= @db_count
BEGIN
    SELECT @db_name = database_name
    FROM #capacity
    WHERE tb_id = @loop_count   

/*****************************************************************************
***get table name,id, and data size                                        ***
******************************************************************************/
    SET @sqlstat = ‘use ‘ +  @db_name   

    SET @sqlstat2 = ‘ insert into #tablestats(database_name,table_name,table_id)
             SELECT ”’+ @db_name + ”’,name, ID FROM SYSOBJECTS WHERE XTYPE =”U”’
    EXEC (@sqlstat + @sqlstat2)

    SET @sqlstat2 = ‘ insert into #tabpage(database_name,table_name,table_id,page_size,used_size)
             select distinct database_name,table_name, table_id, ”page size” = (SELECT isnull(SUM(DPAGES),0)
                  FROM SYSINDEXES
                WHERE SYSINDEXES.INDID < 2 AND
                                      SYSINDEXES.ID = #tablestats.table_id),’
    SET @sqlstat3 = ”’used size” = (SELECT ISNULL(SUM(USED),0)
                FROM SYSINDEXES
                WHERE SYSINDEXES.INDID = 255 AND
                                      SYSINDEXES.ID = #tablestats.table_id)
               from #tablestats ‘
    EXEC (@sqlstat + @sqlstat2+@sqlstat3)

    SET @sqlstat2 = ‘ update #tablestats set data_size = (select LTRIM(STR((page_size + used_size ) ‘
    SET @sqlstat3 = ‘* 8192 / 1024.*’+@projected_size+’,15,0) + ” ” + ”KB”) from  #tabpage ‘
    SET @sqlstat4 = ‘where #tabpage.table_id = #tablestats.table_id and #tabpage.table_name = #tablestats.table_name) from #tablestats ‘
    EXEC (@sqlstat + @sqlstat2+@sqlstat3 + @sqlstat4)
/*****************************************************************************
***get reserved size                                                       ***
******************************************************************************/
    SET @sqlstat2 = ‘ update #tablestats set reserved_size = (SELECT LTRIM(STR(cast(SUM(RESERVED) as bigint) ‘
    SET @sqlstat3 = ‘  * 8192 / 1024.*’+@projected_size+’,300,0) + ” ” + ”KB”) FROM SYSINDEXES ‘
    SET @sqlstat4 = ‘ WHERE SYSINDEXES.INDID IN (0,1,255) AND SYSINDEXES.ID = #tablestats.table_id) from #tablestats ‘
    EXEC (@sqlstat + @sqlstat2+@sqlstat3 + @sqlstat4)
/*****************************************************************************
***get unused size                                                         ***
******************************************************************************/
    SET @sqlstat2 = ‘ update #tablestats set unused_size = (SELECT LTRIM(STR((cast(SUM(RESERVED) as bigint)- SUM(USED)) ‘
    SET @sqlstat3 = ‘ * 8192 / 1024.*’+@projected_size+’,15,0) + ” ” + ”KB”) FROM SYSINDEXES ‘
    SET @sqlstat4 = ‘ WHERE SYSINDEXES.INDID IN (0,1,255) AND SYSINDEXES.ID = #tablestats.table_id) from #tablestats ‘
    EXEC (@sqlstat + @sqlstat2+@sqlstat3 + @sqlstat4)
/*****************************************************************************
***get index size                                                          ***
******************************************************************************/
    DELETE
    FROM #tabpage

    SET @sqlstat2 = ‘ insert into #tabpage(table_id,page_size,used_size,index_size)select table_id, ‘
    SET @sqlstat3 = ‘ ”page size” = (SELECT SUM(DPAGES) FROM SYSINDEXES WHERE SYSINDEXES.INDID < 2 AND SYSINDEXES.ID = #tablestats.table_id), ‘
    SET @sqlstat4 = ‘ ”used size” = (SELECT SUM(convert(dec(15),USED)) FROM SYSINDEXES WHERE SYSINDEXES.INDID in (255) AND SYSINDEXES.ID = #tablestats.table_id), ‘
    SET @sqlstat5 = ‘ ”index_size” = (SELECT SUM(convert(dec(15),USED))FROM SYSINDEXES WHERE SYSINDEXES.INDID in (0,1,255) AND SYSINDEXES.ID = #tablestats.table_id) from #tablestats  ‘
    EXEC (@sqlstat + @sqlstat2+@sqlstat3 + @sqlstat4+@sqlstat5)

    SET @sqlstat2 = ‘ update #tablestats set INDEX_size = (SELECT LTRIM(STR((index_SIZE – (PAGE_SIZE + ISNULL(USED_SIZE,0))) ‘
    SET @sqlstat3 = ‘ * 8192 / 1024.*’+@projected_size+’,15,0) + ” ” + ”KB”) FROM  #TABPAGE ‘
    SET @sqlstat4 = ‘WHERE #tabPAGE.table_id = #tablestats.table_id) from #tablestats’
    EXEC (@sqlstat + @sqlstat2+@sqlstat3 + @sqlstat4)
/*****************************************************************************
***get PK size                                                             ***
******************************************************************************/
    SET @sqlstat2 = ‘ INSERT INTO #PKHOLD(PK_ID,PK_NAME,PARENT_ID) SELECT SO.ID, ‘
    SET @sqlstat3 = ‘ SO.NAME,SO.PARENT_OBJ FROM SYSOBJECTS SO INNER JOIN #tablestats TS ON ‘
    SET @sqlstat4 = ‘ SO.PARENT_OBJ = TS.TABLE_ID WHERE SO.XTYPE = ”PK”’
    EXEC (@sqlstat + @sqlstat2+@sqlstat3 + @sqlstat4)

    UPDATE #tablestats
    SET primary_key_size = index_size
    FROM #PKHOLD  pk INNER JOIN #tablestats tb
              ON pk.PARENT_ID = tb.table_id
/*****************************************************************************
***get number rows                                                         ***
******************************************************************************/
    SET @sqlstat2 = ‘ update #tablestats set number_rows_table = rows*’+@projected_size
    SET @sqlstat3 = ‘ from sysindexes si inner join #tablestats tb on si.id = tb.table_id ‘
    SET @sqlstat4 = ‘ where si.indid < 2 ‘
    EXEC (@sqlstat + @sqlstat2+@sqlstat3 + @sqlstat4)

     INSERT INTO #alltablestats(database_name,table_name,table_id,data_size,
                               reserved_size,unused_size,index_size,
                               primary_key_size,number_rows_table)
    SELECT database_name,table_name,table_id,data_size,
           reserved_size,unused_size,index_size,
           primary_key_size,number_rows_table
    FROM #tablestats
    ORDER BY database_name

     DELETE FROM #tablestats
     DELETE FROM #tabpage
    DELETE FROM #pkhold
    SET @loop_count = @loop_count + 1
 END
/*****************************************************************************
***return results to the screen                                            ***
******************************************************************************/
SELECT database_name,table_name,data_size,
       reserved_size,unused_size,index_size,
       primary_key_size,number_rows_table
FROM  #alltablestats
ORDER BY DATABASE_NAME,TABLE_NAME

 
Leave a comment

Posted by on September 16, 2011 in SQl server Administration

 

Script to check log space

use master
go
Dbcc sqlperf(logspace)
go

 
Leave a comment

Posted by on September 16, 2011 in SQl server Administration