Defaults

Defaults allow you to specify a value to be entered into a column, if one is not otherwise specified. Defaults can be anything that evaluates to a constant, such as a constant, a built-in function, or a mathematical expression. Defaults are of two types: declarative and bound. The two are functionally the same; the difference is in how they are implemented.

Declarative Defaults

A declarative default is just another flavor of constraint, and as such is implemented using the CREATE TABLE and ALTER TABLE commands. Following is an example of adding a DEFAULT constraint to the employee table that enters a value of UNLISTED if no phone number is specified:

ALTER TABLE employee ADD 
  CONSTRAINT df_emp_ph DEFAULT 'UNLISTED' FOR Phone

To remove ...

Get Microsoft® SQL Server™ 2000 Unleashed, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.