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
The WITH clause in SQL was introduced in standard SQL to simplify complex long queries, especially those with JOINs and subqueries. Often interchangeably called CTE or subquery refactoring, a WITH clause defines a temporary data set whose output is available to be referenced in subsequent queries.
Returns true if both expressions are true ; otherwise, false or NULL .
The VALUE function returns the value of the first non-null expression. The schema is SYSIBM. The VALUE function is identical to the COALESCE function. COALESCE should be used for conformance to SQL standard.
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
)
WITH VALUES
applies default values to the null fields
http://technet.microsoft.com/en-us/library/ms187742.aspx and a short blog post about it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With