zoukankan      html  css  js  c++  java
  • 7.索引和数据完整性

    use YGGL
    
    --建立索引
    create index index_dep
    on Employees(DepID)
    
    --建立复合索引
    create index index_com
    on Employees(EmpName,EmpSex)
    
    --建立唯一聚集索引
    create unique clustered index index_uc
    on Employees(EmpID)
    
    --重建索引
    alter index all
      on Employees rebuild
    
    --删除索引
    drop index index_com
     on Employees
    
    --创建表是创建主键约束或唯一约束
     create table Employees5
     (
     EmployeeID int not null unique,
     EmpName varchar(6) not null primary key,--constraint pk_en primay key
     EmpSex bit not null,
     EmpEdu char(3) not null
     )
    
     --修改表时创建主键约束或唯一约束
     alter table Employees5
     add
     constraint uk_es unique(EmpSex)
    
     --删除主键约束或唯一约束
     alter table Employees5
     drop constraint uk_es
    
     --创建表是添加check约束
     create table student
     (
     sName varchar(6) not null,
     sAge int not null
     check(sAge<100 and sAge>0)
     )
    
      create table student1
     (
     sName varchar(6) not null,
     sSex char(2) not null
     check(sSex in('男','女'))
     )
    
     --修改表是添加check约束
     alter table student1
     add 
     constraint ck_age check(sage<100) 
    
     --删除check约束
     alter table student1
     drop constraint ck_age
    
    --外键 foreign key

  • 相关阅读:
    tkinter学习-Lable&Button
    Shell—常见报错问题
    Linux—修改ssh远程登录信息
    Linux—网络管理
    Linux—磁盘管理
    Python—创建进程的三种方式
    Shell—引入外部脚本文件
    Mysql—数据恢复
    Shell—文件内容操作
    Shell—各种括号的用法
  • 原文地址:https://www.cnblogs.com/wangxueliang/p/9346508.html
Copyright © 2011-2022 走看看