zoukankan      html  css  js  c++  java
  • SQL增加约束

    1.主键约束:

    格式为:
    alter table 表格名称 add constraint 约束别名    约束类型 (列名)

    例子:
    alter table table_name add constraint abc000  primary key (id);

    2.check约束:就是给一列的数据进行了限制
    格式:
    alter table 表名称 add constraint 约束别名    约束类型 (列名)

    例子:
    alter table table_name   add constraint abc001 check(age>20);

    3.unique约束:这样的约束就是给列的数据追加的不重复的约束类型

    格式:
    alter table 表名 add constraint 约束别名     约束类型(列名)
    例子:
    alter table table_name add constraint abc002 unique(class);

    4.默认约束:意思很简单就是为此列的数据设置默认值

    格式:
    alter table 表名称 add constraint    约束别名    约束类型   默认值   for  列名

    例子:

    alter table table_name add constraint   abc003     default  99  for score;

    5.外键约束:即当前表的外键,引用外面另一个表的主键,每个值唯一且对应;要建立外键关系,首先要保证用来建立外键关系的列具有唯一性,即具有 UNIQUE 约束

    格式:
    alter table 表名 add constraint   约束别名   约束类型 (列名)   references   引用的表名称 (列名)

    例子:
    alter table table_name add constraint   abc004   foreign key (did)    references   dept (id);

    6. 非空约束:

      即是设置一列值不空

        ALTER TABLE TABLE_NAME     ALTER COLUMN COLUMN_NAME   TYPE_OF_  NOT NULL;
  • 相关阅读:
    vue-resource请求
    vue的生命周期
    Swift-多类型封装
    Swift
    Swift-structures 和 classes 初始化
    iOS-延时加载,延时初始化
    Swift-Closures
    WKWebView-填坑总结
    存档&&解档游戏状态
    循环引用 && weak strong
  • 原文地址:https://www.cnblogs.com/bernard-shen/p/13159179.html
Copyright © 2011-2022 走看看