开发者

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

开发者 https://www.devze.com 2023-03-08 00:11 出处:网络
A default value of a column can be added like this ALTER TABLE [MyTable] ADD DEFAULT ((0)) FOR [MyColumn]

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

精彩评论

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