Binds a user-defined default to a column or user-defined datatype.
sp_bindefault defname, objname [, futureonly]
Existing columns of the user-defined datatype inherit the default defname, unless you specify futureonly.
You cannot bind defaults to computed columns.
sp_bindefault today, "employees.startdate"
sp_bindefault def_ssn, ssn
sp_bindefault def_ssn, ssn, futureonly
You can create column defaults in two ways: by declaring the default as a column constraint in the create table or alter table statement or by creating the default using the create default statement and binding it to a column using sp_bindefault. Using create default, you can bind that default to more than one column in the database.
You cannot bind a default to an SAP ASE server-supplied datatype.
You cannot bind a default to a system table.
Defaults bound to a column or user-defined datatype with the IDENTITY property have no effect on column values. Each time you insert a row into the table, the SAP ASE server assigns the next sequential number to the IDENTITY column.
If binding a default to a column, give the objname argument in the form “table.column”. Any other format is assumed to be the name of a user-defined datatype.
If a default already exists on a column, you must remove it before binding a new default. Use sp_unbindefault to remove defaults created with sp_bindefault. To remove defaults created with create table or alter table, use alter table to replace the default with NULL.
Existing columns of the user-defined datatype inherit the new default unless you specify futureonly. New columns of the user-defined datatype always inherit the default. Binding a default to a user-defined datatype overrides defaults bound to columns of that type; to restore column bindings, unbind and rebind the column default.
Statements that use a default cannot be in the same batch as their sp_bindefault statement.
See also create default, create table, drop default in Reference Manual: Commands.
You must be the table owner or the user datatype owner to execute sp_bindefault. Permission checks do not differ based on the granular permissions settings.
Values in event and extrainfo columns from the sysaudits table are:
Information | Values |
---|---|
Event | 6 |
Audit option | bind |
Command or access audited | sp_bindefault |
Information in extrainfo |
|
Information | Values |
---|---|
Event | 38 |
Audit option | exec_procedure |
Command or access audited | Execution of a procedure |
Information in extrainfo |
|