开发者

What's the difference between a column with a default and a column with a default constraint?

A default value of a column can be added like this

ALTER TABLE [MyTable] ADD DEFAULT ((0)) FOR [MyColumn]

or like this

ALTER TABLE [MyTable] ADD CONSTRAINT [DF_MyTable_MyColumn]  DEFAULT ((0)) FOR开发者_如何转开发 [MyColumn]

What is the difference between the two?


The constraint in the first example will be assigned a name by SQL Server.


SQL Server peculiarly classifies defaults as "constraints". The syntax using the CONSTRAINT keyword allows you to specify a name for the default, which is good practice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜