Skip to content

Latest commit

 

History

History
115 lines (78 loc) · 4.22 KB

sp-unbindefault-transact-sql.md

File metadata and controls

115 lines (78 loc) · 4.22 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs
sp_unbindefault (Transact-SQL)
Unbinds, or removes, a default from a column or from an alias data type in the current database.
markingmyname
maghan
randolphwest
08/21/2024
sql
system-objects
reference
sp_unbindefault_TSQL
sp_unbindefault
sp_unbindefault
TSQL

sp_unbindefault (Transact-SQL)

[!INCLUDE SQL Server]

Unbinds, or removes, a default from a column or from an alias data type in the current database.

Important

[!INCLUDE ssNoteDepFutureAvoid] We recommend that you create default definitions by using the DEFAULT keyword in the ALTER TABLE or CREATE TABLE statements instead.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

sp_unbindefault
    [ @objname = ] N'objname'
    [ , [ @futureonly = ] 'futureonly' ]
[ ; ]

Arguments

[ @objname = ] N'objname'

The name of the table and column or the alias data type from which the default is to be unbound. @objname is nvarchar(776), with no default. [!INCLUDE ssNoVersion] attempts to resolve two-part identifiers to column names first, then to alias data types.

When unbinding a default from an alias data type, any columns of that data type that have the same default are also unbound. Columns of that data type with defaults bound directly to them are unaffected.

Note

@objname can contain brackets [] as delimited identifier characters. For more information, see Database identifiers.

[ @futureonly = ] 'futureonly'

Used only when unbinding a default from an alias data type. @futureonly is varchar(15), with a default of NULL. When @futureonly is futureonly, existing columns of the data type don't lose the specified default.

Return code values

0 (success) or 1 (failure).

Remarks

To display the text of a default, execute sp_helptext with the name of the default as the parameter.

Permissions

To unbind a default from a table column requires ALTER permission on the table. To unbind a default from an alias data type requires CONTROL permission on the type or ALTER permission on the schema to which the type belongs.

Examples

A. Unbind a default from a column

The following example unbinds the default from the hiredate column of an employees table.

EXEC sp_unbindefault 'employees.hiredate';

B. Unbind a default from an alias data type

The following example unbinds the default from the alias data type ssn. It unbinds existing and future columns of that type.

EXEC sp_unbindefault 'ssn';

C. Use the futureonly_flag

The following example unbinds future uses of the alias data type ssn without affecting existing ssn columns.

EXEC sp_unbindefault 'ssn', 'futureonly';

D. Use delimited identifiers

The following example shows using delimited identifiers in @objname parameter. Notice the period as part of the table name. In the sp_unbindefault portion, the object contains two periods; the first is part of the table name, and the second distinguishes the table name from the column name.

--
CREATE TABLE [t.3] (c1 INT);

CREATE DEFAULT default2 AS 0;
GO

EXEC sp_bindefault 'default2', '[t.3].c1';

EXEC sp_unbindefault '[t.3].c1';

Related content