I have been trying to understand what the WITH VALUES
statement does?
I cant seem to find any documentation that explains it properly.
ALTER TABLE Table1
ADD newGuidId UniqueIdentifier NULL CONSTRAINT DF_Guid Default newid()
with values
When you add a nullable column with a default constraint to a table, then all existing rows will get the new column with a NULL
as its value. The defined default values will only be applied to new rows being inserted (if they don't have a value for that column in their INSERT
statement).
When you specify WITH VALUES
, then all existing rows will get that defined default value instead of NULL
If the column you're adding to your new table is non-nullable and has a default constraint, then that default value is applied to all existing rows in the table automatically (no need for WITH VALUES
because the column must have a value other than NULL
)