SQL約束控制語句
SQL約束是SQL數據庫中非常重要的部分,下面介紹的幾個SQL語句用于SQL約束控制,希望可以讓您對SQL約束有更深的認識。
1)禁止所有表SQL約束的SQL語句
select 'alter table '+name+' nocheck constraint all' fromwhere type='U'
2)刪除所有表數據的SQL
select 'TRUNCATE TABLE '+name from sysobjects '
3)恢復所有表SQL約束的SQL
select 'alter table '+name+' check constraint all' from type='U'
4)刪除某字段的SQL約束
declare @name varchar(100)
--DF為約束名稱前綴
selectb.name from syscolumns a,sysobjects b where a.id=object_id('表名') and b.id=a.cdefault '字段名' and b.name like 'DF%'
【編輯推薦】