Here's the generated script from SSMS "Script Table as"->"Create To":
USE [DADatabaseMarch11]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[LoginName](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](255) NOT NULL,
CONSTRAINT [PK_LoginName] 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],
CONSTRAINT [IX_LoginName] UNIQUE NONCLUSTERED
(
[name] 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
SET ANSI_PADDING OFF
GO
I am using SQL 2008 R2 only without any n开发者_运维百科eed for backward compatability.
My QUESTION is: are there pieces of the above that, for practical purposes, can be left out?
ANSI_NULLS http://msdn.microsoft.com/en-us/library/ms188048.aspx
You are not doing anything special with filtered indexes, computed columns etc, so you can drop it.
QUOTED_IDENTIFIER http://msdn.microsoft.com/en-us/library/ms174393.aspx
Very standard names with nary a quote in sight, so it has zero effect here.
ANSI_PADDING http://msdn.microsoft.com/en-us/library/ms187403.aspx
This setting should invariably be on. It is only needed here if you have for whatever reason you have set it to off. Even then, it does not do much, because even if you kept trailing spaces in LoginName.NAME,
where name = 'abc' => will match 'abc ' (spaces stored)
len(name) = 3 => even if name is 'abc '
Because throughout SQL Server, it is already doing funny things with trailing spaces.
The bare minimum you need
CREATE TABLE dbo.LoginName(
id int IDENTITY NOT NULL,
name varchar(255) NOT NULL,
CONSTRAINT PK_LoginName PRIMARY KEY
(
id
),
CONSTRAINT IX_LoginName UNIQUE
(
name
)
)
GO
- You normally only have one filegroup, named "PRIMARY" so those can go
- The index options are defaults, include or change them only if they matter for tuning
- The primary key is by default always clustered unless another one already is
- The unique key is non-clustered since the primary key is already clustered
- []'s are not necessary since no special names are being used
- I left
dbo.
in there, but to be honest, it can go too in 99% of cases - IDENTITY without specifiers is be default (1,1)
精彩评论