use StudentManageDB
go
--创建主键约束 if exists(select * from sysobjects where name='pk_StudentId')
alter table Students drop constraint pk_StudentId
alter table Students add constraint pk_StudentId primary key(StudentId) --创建唯一约束
if exists(select * from sysobjects where name='uq_StudentIdNo')
alter table Students drop constraint uq_StudentIdNo
alter table Students add constraint uq_StudentIdNo unique(StudentIdNo) --创建检查约束
if exists(select * from sysobjects where name='ck_Age')
alter table Students drop constraint ck_Age
alter table Students add constraint ck_Age check(Age between 18 and 25) if exists(select * from sysobjects where name='ck_PhoneNumber')
alter table Students drop constraint ck_PhoneNumber
alter table Students add constraint ck_PhoneNumber check(len(PhoneNumber)=11) update Students set PhoneNumber='' where StudentId=10000
select * from Students --创建默认值
if exists(select * from sysobjects where name='df_StudentAddress')
alter table Students drop constraint df_StudentAddress
alter table Students add constraint df_StudentAddress default('地址不详') for StudentAddress insert into Students (StudentName,Gender,Birthday,Age,StudentIdNo ,PhoneNumber,
StudentAddress,ClassId)
values('李小璐','女','1989-01-12',24,120229198901121315, '',default,1) insert into Students (StudentName,Gender,Birthday,Age,StudentIdNo ,PhoneNumber,
ClassId)
values('李小璐','女','1989-01-12',24,120229198901121316, '',1) --外键约束
insert into StudentClass (ClassId,ClassName) values(1,'软件1班')
if exists(select * from sysobjects where name='fk_ClassId')
alter table Students drop constraint fk_ClassId
alter table Students add constraint fk_ClassId foreign key (ClassId) references StudentClass(ClassId) select * from studentClass

最新文章

  1. Unity3D NGUI刮刮卡效果
  2. Cocos学习-----Cocos2Dx安装
  3. Linux下SVN安装与基本操作
  4. osharp3 整合 dbcontextscope 文章2 将dbcontext的创建收回到ioc管理
  5. Jersey框架一:Jersey RESTful WebService框架简介
  6. 快速解决Canvas.toDataURL 图片跨域的问题
  7. IOS 7 Study - UIActivityViewController(Presenting Sharing Options)
  8. avalon学习笔记一 列表及条件过滤
  9. Java中的流程控制(二)
  10. Hibernate基础学习(一)—初识Hibernate
  11. Simpson积分(BZOJ2178)
  12. 《Java技术》的第二次作业
  13. 把一个机器上1天内新增的文件用rsync传送到另外一台机器
  14. MySQL delete语句的问题
  15. Win7+ 电脑 休眠 自动唤醒
  16. mysql常用运算符
  17. 【待完成】[MapReduce_9] MapReduce 的 Shuffle 机制
  18. Linux文件的时间
  19. Android: TextView 及其子类通过代码和 XML 设置字体大小的存在差异的分析
  20. MySQL只有.frm文件恢复表结构

热门文章

  1. python——psutil的使用(获取进程信息)
  2. 用IBM MQ中间件开发碰到的MQRC_NOT_AUTHORIZED(2035)问题
  3. numpy 笔记
  4. ~ # himm -sh: himm: not found的解决方法
  5. css 如何实现图片等比例缩放
  6. :nth-of-type(n) 与 :nth-child(n) 区别
  7. netBeans 修改新建php文件头部注释模板
  8. DevOps需要的工具
  9. php解析url并得到url中的参数及获取url参数
  10. Delphi常用API,API函数