sp_bindefault

Binds a user-defined default to a column or user-defined datatype.

Syntax

sp_bindefault defname, objname [, futureonly]

Parameters

Examples

Usage

There are additional considerations when using sp_bindefault:
  • 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.

Permissions

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.

Auditing

Values in event and extrainfo columns from the sysaudits table are:

InformationValues
Event

6

Audit option

bind

Command or access audited

sp_bindefault

Information in extrainfo
  • Roles – Current active roles

  • Keywords or options – NULL

  • Previous value – NULL

  • Current value – NULL

  • Other information – Name of default

  • Proxy information – Original login name, if set proxy in effect

InformationValues
Event

38

Audit option

exec_procedure

Command or access audited

Execution of a procedure

Information in extrainfo
  • Roles – Current active roles

  • Keywords or options – NULL

  • Previous value – NULL

  • Current value – NULL

  • Other information – All input parameters

  • Proxy information – Original login name, if set proxy in effect

Related reference
sp_unbindefault