Wednesday, August 26, 2015

ID Identity as Primary Key Cluster

Here is some sample code I give programmers. A composite PK is often a touch faster but sometimes a PK like this is the best alternative. Everything even Inserts are faster with a Primary Key and Cluster

CREATE TABLE [dbo].[TableName](
[ID] [int] IDENTITY(1,1) NOT NULL,
All your columns remember the last column statement has a comma after it,
 CONSTRAINT [PK_TableName] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

0 Comments:

Post a Comment

<< Home