1

SQL Server 200x/2012 中的以下 2 个 CREATE TABLE 语句之间有什么区别吗?我从两个不同的表生成了这个脚本,一个定义了一个键名(PK_Table1),而另一个有某种随机生成的数字与之关联(PK_Table1_1084F446)。

CREATE TABLE [dbo].[Table1](
    [ID] [uniqueidentifier] NOT NULL,
    <<Other Column declaration here>>
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
Few more non-clustered indexes declaration here


CREATE TABLE [dbo].[Table1](
    [ID] [uniqueidentifier] NOT NULL,
    <<Other Column declaration here>>
 CONSTRAINT [PK_Table1] 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
Few more non-clustered indexes declaration here
4

1 回答 1

1

它的工作方式相同,但自然名称更方便:

1) 更改约束时,您可以轻松引用它(如果您给出了合理的名称);

2)当查询由于约束而失败时,会显示该约束的名称,因此您可以轻松了解导致错误的原因(如果您给出了合理的名称)。

于 2012-06-20T09:53:21.070 回答