在當(dāng)前數(shù)據(jù)庫中為列或者用戶定義數(shù)據(jù)類型解除(刪除)默認(rèn)值綁定。
sp_unbindefault [@objname =] 'object_name'
[, [@futureonly =] 'futureonly_flag']
[@objname =] 'object_name'
是要解除默認(rèn)值綁定的表和列或者用戶定義數(shù)據(jù)類型的名稱。object_name 的數(shù)據(jù)類型為 nvarchar(776),無默認(rèn)值。如果參數(shù)不是 table.column 的形式,則假定 object_name 為用戶定義數(shù)據(jù)類型。當(dāng)為用戶定義數(shù)據(jù)類型解除默認(rèn)值綁定時(shí),所有屬于該數(shù)據(jù)類型并具有相同默認(rèn)值的列也同時(shí)解除默認(rèn)值綁定。對(duì)屬于該數(shù)據(jù)類型的列,如果其默認(rèn)值直接綁定到列上,則該列不受影響。
說明 object_name 中可以含有 [ and ] 字符作為分隔標(biāo)識(shí)符。有關(guān)更多信息,請(qǐng)參見分隔標(biāo)識(shí)符。
[@futureonly =] 'futureonly_flag'
僅用于解除用戶定義數(shù)據(jù)類型默認(rèn)值的綁定。futureonly_flag 的數(shù)據(jù)類型為 varchar(15),其默認(rèn)值為 NULL。當(dāng)參數(shù) futureonly_flag 為 futureonly 時(shí),現(xiàn)有的屬于該數(shù)據(jù)類型的列不會(huì)失去指定默認(rèn)值。
0(成功)或 1(失?。?/P>
若要顯示默認(rèn)值的文本,請(qǐng)以該默認(rèn)值的名稱為參數(shù)執(zhí)行存儲(chǔ)過程 sp_helptext。
解除默認(rèn)值綁定時(shí),如果默認(rèn)值綁定到列,則綁定信息從表 syscolumns 中刪除。如果默認(rèn)值綁定到用戶定義數(shù)據(jù)類型,則綁定信息從表 systypes 中刪除。
只有 sysadmin 固定服務(wù)器角色、db_owner 和 db_ddladmin 固定數(shù)據(jù)庫角色的成員以及表所有者才能執(zhí)行 sp_unbindefault。
下例為表 employees 的 hiredate 列解除默認(rèn)值綁定。
EXEC sp_unbindefault 'employees.hiredate'
下例為用戶定義數(shù)據(jù)類型 ssn 解除默認(rèn)值綁定。這將為該數(shù)據(jù)類型的現(xiàn)有列和將來的列解除綁定。
EXEC sp_unbindefault 'ssn'
下例為用戶定義數(shù)據(jù)類型 ssn 解除默認(rèn)值綁定,現(xiàn)有的 ssn 列不受影響。
EXEC sp_unbindefault 'ssn', 'futureonly'
此示例顯示了在 object_name 中分隔標(biāo)識(shí)符的使用。
CREATE TABLE [t.3] (c1 int) -- Notice the period as part of the table
-- name.
CREATE DEFAULT default2 AS 0
GO
EXEC sp_bindefault 'default2', '[t.3].c1'
-- The object contains two periods;
-- the first is part of the table name and the second
-- distinguishes the table name from the column name.
EXEC sp_unbindefault '[t.3].c1'
相關(guān)文章