微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SQLSERVER添加删除列、添加修改删除各种约束

 
 
--添加
alter table emp_info add test int;
 
--删除
alter table emp_info drop column tableid;
 
--重命名表名
exec sp_rename 'calss','class';
 
--重命名列明
exec sp_rename 'class.calssname','classname','COLUMN';
 
--改变列长度
 
alter table emp_info alter column address nchar(100)
 
 
---------------------------------------
添加约束

添加主键
add constraint PK_stuNo primary key ( studentNO ) studentNo --studentNo 列明
 
添加非空
alter table student
add constraint LoginPwd check ( LoginPwd is not null)
 
认约束
alter table student
add constraint DF_address default ( '地址不详' ) for address ;
 
alter table student student
�检查约束
alter table Student
add constraint CK_borndate CHECK(BornDate>='1980-01-01')
 
�唯一约束
alter table student
add constraint UQ_identityCard Unique ( identityCard )
 
�外键约束
alter table result
add constraint FK_stuNo foreign key ( studentNo ) �外键列名
references student ( studentNo ) �student 主表
删除约束
alter table student
drop constraint CK_borndate
 
 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐