Friday, October 23, 2009

What is the DEFAULT constraint in SQL Server?

A DEFAULT constraint, like all constraints, becomes an integral part of the table definition. It defines what to do when new row is inserted that does not include data for the column on which you have defined the DEFAULT constraint. You can either define it as a literal value(like default salary to zero or UNKNOWN for a string column) or as one of several values such as GETDATE().
The main things to understand about a DEFAULT constraint are -

1. DEFAULTs are only used in INSERT statements- They are ignored for UPDATE and DELETE statements.
2. If any value is supplied in the INSERT then the default is not used.
3. If no values supplied the default will always be used.

Share This!

No comments:

Powered By Blogger · Designed By Seo Blogger Templates