Reputation: 217
What is the point of default values in a column of a table? According to http://technet.microsoft.com/en-us/library/ms187872.aspx
You can specify a default value that will be entered in the column in SQL Server 2012 by using SQL Server Management Studio or Transact-SQL. If you do not assign a default value and the user leaves the column blank, then:
- If you set the option to allow null values, NULL will be inserted into the column.
- If you do not set the option to allow null values, the column will remain blank, but the user will not be able to save the row until they supply a value for the column.
I don't get it! If you don't allow nulls on a column surely it should insert a default value in that column if not supplied by the user. So why doesn't it?
Upvotes: 0
Views: 1372
Reputation: 60493
You must have missed a part of the doc.
You can specify a default value that will be entered in the column in SQL Server 2012 by using SQL Server Management Studio or Transact-SQL. If you do NOT assign a default value and the user leaves the column blank, then: If you set the option to allow null values, NULL will be inserted into the column. If you do not set the option to allow null values, the column will remain blank, but the user will not be able to save the row until they supply a value for the column.
So if you DO assign a default value, it will be used as assignment when user leaves the column blank.
The "little bit weird thing" is that the doc explains first what will happen if you don't use the DEFAULT (which is probably not what you're waiting for : you'd like to know what will happen when you use it). Have also been confused at my first "too fast" reading.
Upvotes: 7