solving sql server problems for millions of dbas and developers since 2006



SQL Server DBA Tips SQL Server Developer Tips SQL Server Business Intelligence Tips SQL Server Career Tips SQL Server Tip Categories SQL Server Tutorials SQL Server Webcasts SQL Server Whitepapers SQL Server Tools SQL Server Questions and Answers MSSQLTips Authors About MSSQLTips SQL Server User Groups MSSLQTips Giveaways MSSQLTips Advertising Options

MSSQLTips Facebook Page MSSQLTips LinkedIn Page MSSQLTips RSS Feed MSSQLTips Twitter Page MSSQLTips Google+ Page

SQL Product Highlight

SQL Sentry, Inc. - SQL Sentry Performance Advisor for SQL Server

SQL Sentry Performance Advisor for SQL Server delivers an advanced performance dashboard with relevant Windows and SQL Server metrics in a single view along with detailed insight of heavy SQL, blocking, deadlocks, and disk bottlenecks. Performance Advisor is packed with ground-breaking features that are not found in any other performance monitoring software, all designed with the singular goal of simplifying the process of optimizing your SQL Server performance.

Learn more!








Index Builds in SQL Server 2000 vs SQL Server 2005

By: | Read Comments | Print

Jeremy is the CTO @ Edgewood Solutions, co-founder of MSSQLTips.com and SQL Server MVP since 2009.



Related Tips: More

Problem
Among many other changes between SQL Server 2000 to 2005, the index creation code has some subtle changes that are important to know and handle appropriately in scripts.  It is important to be aware of these changes due to the beneficial performance gains with proper indexes.  Check out the index creation differences between SQL Server 2000 and 2005.

Solution
When transitioning from SQL Server 2000 and 2005 be sure you are using the correct syntax for your next database design.  Below outlines the T-SQL commands to build many of the common indexes needed to support your database design to achieve high performance and high levels of concurrency.

SQL Server 2000 SQL Server 2005
CREATE INDEX - Clustered

CREATE CLUSTERED INDEX au_id_clidx
ON Authors (au_id)
GO

CREATE INDEX - Clustered

CREATE CLUSTERED INDEX IX_dbo_Customer_CustID
ON dbo.Customer(CustID);
GO

CREATE INDEX - Non-clustered

CREATE INDEX au_id_ncidx
ON Authors (au_id)
GO

CREATE INDEX - Non-clustered

CREATE INDEX IX_dbo_Customer_CustName
ON dbo.Customer(CustName);
GO

CREATE INDEX - Unique

CREATE UNIQUE INDEX au_id_unidx
ON Authors (au_id)
GO

CREATE INDEX - Unique

CREATE UNIQUE INDEX IX_unq_dbo_Customer_CustID
ON dbo.Customer(CustID);
GO

CREATE INDEX - Non-clustered Composite (Multiple columns in the index)

CREATE UNIQUE INDEX au_id_au_lname_ncidx
ON Authors (au_id, au_lname)
GO

CREATE INDEX - Non-clustered Composite (Multiple columns in the index)

CREATE NONCLUSTERED INDEX IX_dbo_Customer_CustID_CustName_CustZipCode
ON dbo.Customer(CustID, CustName, CustZipCode);
GO

CREATE INDEX - Non-clustered with 80% fill factor (Percentage of page full)

CREATE INDEX au_id_ncidx
ON Authors (au_id)
WITH FILLFACTOR = 80
GO

CREATE INDEX - Non-clustered with 80% fill factor (Percentage of page full)

CREATE NONCLUSTERED INDEX IX_dbo_Customer_CustID
ON dbo.Customer(CustID)
WITH (FILLFACTOR = 80);
GO

CREATE INDEX - Non-clustered ascending order

CREATE INDEX au_id_ncidx
ON Authors (au_id ASC)
GO

CREATE INDEX - Non-clustered ascending order

CREATE NONCLUSTERED INDEX IX_dbo_Customer_CustID
ON dbo.Customer (CustID ASC);
GO

CREATE INDEX - Non-clustered descending order

CREATE INDEX au_id_ncidx
ON Authors (au_id DESC)
GO

CREATE INDEX - Non-clustered descending order

CREATE NONCLUSTERED INDEX IX_dbo_Customer_CustID8
ON dbo.Customer (CustID DESC);
GO

CREATE INDEX  - IGNORE_DUP_KEY

CREATE UNIQUE INDEX au_id_unq_ind
ON Authors(au_id)
WITH IGNORE_DUP_KEY
GO

CREATE INDEX - IGNORE_DUP_KEY

CREATE UNIQUE INDEX AK_Customer_CustID
ON dbo.Customer(CustID)
WITH (IGNORE_DUP_KEY = ON);
GO

CREATE INDEX  -  DROP_EXISTING

CREATE INDEX au_id_ind
ON Authors(au_id)
WITH DROP_EXISTING
GO

CREATE INDEX -  DROP_EXISTING

CREATE NONCLUSTERED INDEX AK_Customer_CustID
ON dbo.Customer(CustID)
WITH (DROP_EXISTING = ON);
GO

CREATE INDEX  - STATISTICS_NORECOMPUTE

CREATE INDEX au_id_ind
ON Authors(au_id)
WITH STATISTICS_NORECOMPUTE
GO

CREATE INDEX - STATISTICS_NORECOMPUTE

CREATE NONCLUSTERED INDEX IDX_Customer_CustID
ON dbo.Customer(CustID)
WITH (STATISTICS_NORECOMPUTE = ON);
GO

CREATE INDEX  - SORT_IN_TEMPDB

CREATE INDEX au_id_ind
ON Authors(au_id)
WITH SORT_IN_TEMPDB
GO

CREATE INDEX - SORT_IN_TEMPDB

CREATE NONCLUSTERED INDEX IDX_Customer_CustID
ON dbo.Customer(CustID)
WITH (SORT_IN_TEMPDB = ON);
GO

CREATE INDEX - MAXDOP

Not available.

CREATE INDEX - MAXDOP

CREATE NONCLUSTERED INDEX IDX_Customer_CustID11
ON dbo.Customer(CustID)
WITH (MAXDOP = 4);
GO

Next Steps



Related Tips: More | Become a paid author


Last Update: 9/7/2006

Share: Share 






Comments and Feedback:


Post a Comment or Question

Keep it clean and stay on the subject or we may delete your comment.
Your email address is not published. Required fields are marked with an asterisk (*)

*Name   *Email   Notify for updates
Comments
*Enter Code refresh code


 
Sponsor Information
"SQL doctor ROCKS! As soon as I ran it, problems that have been giving me headaches were identified and cured."

SQL Monitor – For database professionals who need results on Day One. Try it online.

SQL Servers keeping you up at night? Contact expert SQL Server consultants for a Health Check.

Find and Fix SQL issues with Foglight Performance Analysis. Get a free copy.

Solving SQL Server problems for millions of DBAs and Devs since 2006. Join now.

Free web casts for DBAs and Developers on Performance Tuning, Development, Administration and more....


Copyright (c) 2006-2012 Edgewood Solutions, LLC All rights reserved
privacy | disclaimer | copyright | advertise | about
authors | contribute | feedback | giveaways | user groups
Some names and products listed are the registered trademarks of their respective owners.


Edgewood Solutions LLC | MSSharePointTips.com | MSSQLTips.com