码迷,mamicode.com
首页 > 数据库 > 详细

SQL Server 删除表的默认值约束

时间:2017-12-28 12:04:49      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:unique   前缀   primary   name   sele   post   存储过程   cts   关联   

首先查出字段的默认值约束名称,然后根据默认值约束名称删除默认值约束

declare @constraintName varchar(200)

select @constraintName = b.name from syscolumns a,sysobjects b where a.id=object_id(TB_KYSubProject) and b.id=a.cdefault and a.name=Final_Belong_Programme and b.name like DF%

SELECT @constraintName

exec(alter table TB_KYSubProject drop constraint +@constraintName)

 

注意:

1.sql中constraint 前缀PK、UK、DF、CK、FK:

PK是primary key缩写,主键约束

UK是unique key缩写,唯一约束

CK是check缩写,检查约束

FK是foreign缩写,主外键关系

DF是default缩写,默认值约束

 

2.syscolumns

cdefault :int 该列的默认值 ID。

id:int 该列所属的表对象 ID,或与该参数关联的存储过程 ID。

name:sysname 列名或过程参数的名称。 

 

3.object_id函数

该函数会返回指定对象的ID值

SQL Server 删除表的默认值约束

标签:unique   前缀   primary   name   sele   post   存储过程   cts   关联   

原文地址:https://www.cnblogs.com/Zev_Fung/p/8133937.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!