Binds a default to a column or to a user-defined datatype.
sp_bindefault defname, objname [, futureonly]
where
First use the CREATE DEFAULT statement to create a default. Then execute the sp_bindefault system stored procedure to bind the default to a column or to a user-defined datatype in the current database. You can bind a new default to a column or to a user-defined datatype with sp_bindefault without unbinding an existing default. The old default is overridden. You cannot bind a default to a SQL Server - supplied datatype.
Existing columns of the user-defined datatype inherit the new default unless they have a default bound directly to them or unless the futureonly option is used. New columns of the user-defined datatype always inherit the default.
The default must be compatible with the datatype of the column. For example, you cannot use "N/A" as a default for a numeric column. If the default is not compatible with the column to which you've bound it, SQL Server returns an error message when it tries to insert the default value (not when you bind it). You cannot bind a default to a column that already has a DEFAULT constraint.
When you bind a default to a column, information is added to the syscolumns table. When you bind a default to a user-defined datatype, information is added to the systypes table.
Assuming that a default named today has been defined in the current database by the CREATE DEFAULT statement, this example binds the default to the startdate column of the employees table. Whenever a row is added to the employees table and data for the startdate column is not supplied, the column gets the value of the default today.
sp_bindefault today, 'employees.startdate'
Assuming that a default named def_ssn and a user-defined datatype named ssn exist, this example binds the default def_ssn to the ssn user-defined datatype. The default is inherited by all columns that are assigned the user-defined datatype ssn when a table is created. Existing columns of type ssn also inherit the default def_ssn unless you specify futureonly (which prevents existing columns of that user-defined datatype from inheriting the default), or unless the column has a default bound directly to it. Defaults bound to columns always take precedence over those bound to datatypes.
sp_bindefault def_ssn, ssn
This example binds the default def_ssn to the user-defined datatype ssn. Because futureonly is specified, no existing columns of type ssn are affected.
sp_bindefault def_ssn, ssn, FUTUREONLY
Execute permission defaults to the object owner.
syscolumns, sysobjects, systypes
CREATE DEFAULT | sp_unbindefault |
DROP DEFAULT |