4 回答
TA貢獻1847條經驗 獲得超11個贊
在查詢分析器里邊執行
alter table 表名
drop constraint 約束名
查看表的約束名執行
sp_helpconstraint 表名
第二個結果集就列出了表的約束,constraint_name就是約束名
或者執行
sp_help 表名
一般第三個結果集中constraint_name就表示相應的約束名。
TA貢獻1810條經驗 獲得超5個贊
這里我給一個方法
注意一個前提,要刪除約束,必須要知道它的約束名
首先你這里的CHECK沒有約束名,這表示系統會自動給你生成一個約束名,所以你首先要查找這個約束名,可以用
sp_help student2
這個語句可以查看student2 表的所有屬性,當然也包括約束名
然后就可以執行刪除操作了
Alter table student2
drop constraint (約束名)
TA貢獻1862條經驗 獲得超7個贊
刪除約束的語法如下:
Alter Table 表名
Drop Constraint 約束名
附加:在創建表的時候同時添加約束的寫法:
use stuDB
go
if exists(select * from Sysobjects where name = 'stuInfo')
drop table stuInfo
go
create table stuInfo
(
stuName varchar(20) not null primary key(stuName)
,stuID int not null unique(stuID)
,stuAddress varchar(20) not null default('地址不詳')
,stuAge int not null check(stuAge between 15 and 40)
)
- 4 回答
- 0 關注
- 2581 瀏覽
添加回答
舉報
