By Cihan Biyikoglu
Technical Reviewers: Lindsey Allen, Peter Scharlock, Burzin Patel, Eric Hanson, Mark Souza, Sanjay Mishra, Michael Thomassy
SQL Server 2005 has hundreds of new and improved components. Some of these improvements get a lot of the spotlight. However there is another set that are the hidden gems that help us improve performance, availability or greatly simplify some challenging scenarios. This paper lists the top 10 such features in SQL Server 2005 that we have discovered through the implementation with some of our top customers and partners.
The order in the list does not have much significance except the specific instances we used them and the impact we saw. I will use a practical analogy; I started with the utility-knife size features that can help make life very easy at the right moment and build up to chain-saw size features that can help you implement a full scenario.
TableDiff.exe
Table Difference tool allows you to discover and reconcile differences between a source and destination table or a view. Tablediff Utility can report differences on schema and data. The most popular feature of tablediff is the fact that it can generate a script that you can run on the destination that will reconcile differences between the tables. TableDiff.exe takes 2 sets of input;
TableDiff was intended for replication but can easily apply to any scenario where you need to compare data and schema.
You can find more information about command line utilities and the Tablediff Utility in Books Online for SQL Server 2005.
Triggers for Logon Events (New in Service Pack 2)
CREATE TRIGGER connection_limit_trigger ON ALL SERVER FOR LOGON AS BEGIN INSERT INTO logon_info_tbl SELECT EVENTDATA() END;
You can find more information about this feature in updated Books Online for SQL Server Services Pack 2 un the heading “Logon Triggers”.
Boosting performance with persisted-computed-columns (pcc).
Query
SELECT [Ticker] ,[Date] , [DayHigh] ,[DayLow] ,[DayOpen] ,[Volume] ,[DayClose] ,[DayAdjustedClose], CASE WHEN volume > 200000000 and dayhigh-daylow /daylow > .05 THEN 'heavy volatility' WHEN volume > 100000000 and dayhigh-daylow /daylow > .03 THEN 'volatile' WHEN volume > 50000000 and dayhigh-daylow /daylow > .01 THEN 'fair' ELSE 'light' END as [DayType] FROM dbo.MarketData WHERE CASE WHEN volume > 200000000 and dayhigh-daylow /daylow > .05 THEN 'heavy volatility' WHEN volume > 100000000 and dayhigh-daylow /daylow > .03 THEN 'volatile' WHEN volume > 50000000 and dayhigh-daylow /daylow > .01 THEN 'fair' ELSE 'light' END = 'heavy volatility'
Table Schema
CREATE TABLE [dbo].[MarketData]( [ID] [bigint] IDENTITY(1,1) NOT NULL, [Ticker] [nvarchar](5) NOT NULL, [Date] [datetime] NOT NULL, [DayHigh] [decimal](38, 6) NOT NULL, [DayLow] [decimal](38, 6) NOT NULL, [DayOpen] [decimal](38, 6) NOT NULL, [Volume] [bigint] NOT NULL, [DayClose] [decimal](38, 6) NOT NULL, [DayAdjustedClose] [decimal](38, 6) NOT NULL, -- PERSISTED COMPUTED COLUMN -- [DayType] AS ( CASE WHEN volume > 200000000 and dayhigh-daylow /daylow > .05 THEN 'heavy volatility' WHEN volume > 100000000 and dayhigh-daylow /daylow > .03 THEN 'volatile' WHEN volume > 50000000 and dayhigh-daylow /daylow > .01 THEN 'fair' ELSE 'light' END) PERSISTED NOT NULL ) ON [PRIMARY]
Output From The Sys.Dm_Exec_Query_Stats Dynamic Management View (DMV)
See full-sized image.
In the above picture, the output from sys.dm_exec_query_stats dynamic management view shows the difference in CPU and IO statistics between the same query hitting MarketData_Computed and MarketData tables. Line 1 represents the query run against the table with the persisted computed column. Line 2 is the table without the persisted computed column. With the complex expression pre-calculated in the DayType column, total worker time and overall elapsed time is lower compared to the table without the DayType persisted computed column.
Another way to verify that the persisted computed column is utilized, is to use the execution plan and look at the scan or the seek operator for the table with the computed column and check the output list, which should contain the column. In the example below you can see the DayType, the name for the PCC, in the output list under #9.
DEFAULT_SCHEMA setting in sys.database_principles
In SQL Server 2005, the following query when executed by user1 that has a DEFAULT_SCHEMA of ‘dbo’ will directly resolve to dbo.tab1, instead of the extra search for user1.tab1.
SELECT * FROM tab1
Whereas the same query will search for ‘user1.tab1’ in SQL Server 2000 and if that does not exist it will resolve to ‘dbo.tab1’.
Forced Parameterization
Vardecimal Storage Format
master.dbo.sp_estimate_rowsize_reduction_for_vardecimal ‘tablename’
exec sys.sp_db_vardecimal_storage_format N'databasename', N'ON'
exec sp_tableoption 'tablename', 'vardecimal storage format', 1
Indexing made easier with SQL Server 2005
Figuring out the most popular queries in seconds
Scalable Shared Databases
Book Online for SQL server 2005 contains details on Scalable Shared Databases. Steps to setup: http://support.microsoft.com/kb/910378
Book Online for SQL server 2005 contains details on Scalable Shared Databases.
Steps to setup:
http://support.microsoft.com/kb/910378
Soft-NUMA
I've talked about the SQLCAT team before and the great content they produce , you may have had a chance
I've talked about the SQLCAT team before and the great content they produce , you may have had a