Specifies a value to insert in a column (or in all columns of a user-defined datatype) if no value is explicitly supplied at insert time.
create default [or replace] [owner.]default_name as constant_expression
When you use or replace, if the specified default name already exists, then it is replaced with the new default definition. The object name and ID remain the same.
When you use or replace, the definition of the default can be changed when the default is replaced. The new default value overrides the old default.
create default D1 as @@spid
create default phonedflt as "UNKNOWN"
sp_bindefault phonedflt, "authors.phone"
No entry is different from a null value entry. To get the default, issue an insert command with a column list that does not include the column that has the default.
create default todays_date as getdate ()
create default phonedflt as "UNKNOWN" select object_id("phonedflt") ----------- 1001051571
create or replace default phonedflt as "999-999-9999" select object_id("phonedflt") ----------- 1001051571
Bind a default to a column or user-defined datatype—but not an SAP ASE server-supplied datatype—with sp_bindefault.
You can bind a new default to a datatype without unbinding the old one. The new default overrides and unbinds the old one.
create default performs error checking for check constraints before it creates the default.
To hide the source test of a default, use sp_hidetext.
See also sp_bindefault, sp_help, sp_helptext, sp_rename, sp_unbindefault in Reference Manual: Procedures.
ANSI SQL – Compliance level: Transact-SQL extension.
Use the default clause of the create table statement to create ANSI SQL-compliant defaults.
Any user who impersonates the default owner through an alias or setuser cannot replace the default.
The permission checks for create default differ based on your granular permissions settings.
Setting | Description |
---|---|
Enabled | With granular permissions enabled, you must have the create default privilege to create a default. To create a default for another user, you must have the create any default privilege. To replace the default, you must be the default owner. |
Disabled | With granular permissions disabled, you must be the database owner, a user with sa_role, or have the create default privilege to create a default. To create a default for another user, you must have sa_role. To replace the default, you must be the default owner. |
Values in event and extrainfo columns of sysaudits are:
Information | Values |
---|---|
Event | 14 |
Audit option | create |
Command or access audited | create default |
Information in extrainfo |
|