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.
精彩评论