加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

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

发布时间:2020-12-12 14:01:51 所属栏目:MsSql教程 来源:网络整理
导读:? ? --添加列 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 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 ? ? 转自 http://www.zhjie.net/sqlserver-add-various-constraints.htm

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读