SSMS 生成的命令(ansi nulls、quoted ident、ansi pad 等)的重要性是什么?
这是从 SSMS“脚本表为”->“创建到”生成的脚本:
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
我仅使用 SQL 2008 R2,不需要向后兼容性。
我的问题是:出于实际目的,上述内容中是否有可以省略的部分?
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 need for backward compatability.
My QUESTION is: are there pieces of the above that, for practical purposes, can be left out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ANSI_NULLS http://msdn.microsoft.com/en -us/library/ms188048.aspx
您没有对过滤索引、计算列等执行任何特殊操作,因此您可以删除它。
QUOTED_IDENTIFIER http://msdn.microsoft.com/en -us/library/ms174393.aspx
非常标准的名称,看不到任何引号,因此它在这里的效果为零。
ANSI_PADDING http://msdn.microsoft.com/en -us/library/ms187403.aspx
此设置应始终打开。仅当您出于某种原因将其设置为关闭时,才需要在此处使用它。即便如此,它也没有做太多事情,因为即使你在 LoginName.NAME 中保留尾随空格,
因为在整个 SQL Server 中,它已经在使用尾随空格做一些有趣的事情了。
您需要的最低限度
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,
Because throughout SQL Server, it is already doing funny things with trailing spaces.
The bare minimum you need
dbo.
in there, but to be honest, it can go too in 99% of cases