1)禁止所有表約束的SQLselect 'alter table '+name+' nocheck constraint all' from sysobjects where type='U'
2)刪除所有表數據的SQLselect 'TRUNCATE TABLE '+name from sysobjects where type='U'
3)恢復所有表約束的SQLselect 'alter table '+name+' check constraint all' from sysobjects where type='U'
4)刪除某字段的約束declare @name varchar(100)--DF為約束名稱前綴select @name=b.name from syscolumns a,sysobjects b where a.id=object_id('表名') and b.id=a.cdefault and a.name='字段名' and b.name like 'DF%'--刪除約束alter table 表名 drop constraint @name--為字段添加新默認值和約束ALTER TABLE 表名 ADD CONSTRAINT @name DEFAULT (0) FOR [字段名]對字段約束進行更改--刪除約束ALTER TABLE tablenameDrop CONSTRAINT 約束名--修改表中已經存在的列的屬性(不包括約束,但可以為主鍵或遞增或唯一)ALTER TABLE tablename alter column 列名 int not null--添加列的約束ALTER TABLE tablenameADD CONSTRAINT DF_tablename_列名 DEFAULT(0) FOR 列名--添加范圍約束alter table tablename add check(性別 in ('M','F'))
詳細請參考:http://www.codesky.net/article/201008/145137.html
新聞熱點
疑難解答