So, here is a test for fun on SQL SERVER 2012. I have a test table, you could choose any table you have in your local.
Then I add a NOT NULL column with default constraint:
alter table test add new_col8 nvarchar(25) not null constraint df_new_col8 default('aaa');
It won't be surprised to see the value get populated but the physical size is still 0. You could refer to the scripts in Why does ALTER COLUMN to NOT NULL cause massive log file growth?.
I used following script and you need to change it a bit when you tested it.
DBCC IND ('master', 'test', 0);
DBCC TRACEON (3604);
GO
DBCC PAGE ('master', 1, 692, 3);
GO
Now, I decided to drop the default constraint. I checked the table again, but the value stays but the physical size is still 0!
alter table test drop constraint df_new_col8;
I checked the sys.default_constraints table and sys.columns table, there is no clue for this default value. How does SQL SERVER still get the default value?!
null! – Colin 't Hart Feb 02 '15 at 08:37NOT NULL. You have to specific the value. I also tried usingDEFAULTbut it won't help. – zhongxiao37 Feb 02 '15 at 08:50sys.columnsandsys.default_constraints. Where does the default values come from? – zhongxiao37 Feb 02 '15 at 09:08