zoukankan      html  css  js  c++  java
  • enum/set 约束

    enum  单选行为

    set    对选行为

    create table t8(
    id int,
    name char(18),
    gender enum('nale','female'));

    create table t10(
    id int,
    name char(18),
    hobby set('film','aiai','dance'),
    time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
    );

    约束:某一个字段不要为空。

    无符号的   只和数字有关     int   unsigned

    不能为空   not  null

    设置严格模式:
    不支持对not null字段插入null值
    不支持对自增长字段插入”值
    不支持text字段有默认值

    直接在mysql中生效(重启失效):
    mysql>set sql_mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";

    配置文件添加(永久失效):
    sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

    not null不生效

    默认值   default

    不能重复 唯一约束   unique     第一个被定义为非空+唯一的那一列会成为这张表的primary key    一张表只能定义一个主键

    自增    auto_increment

    只能对数字有效,自带非空约束,

    至少是unique的约束之后才能使用auto_increment

    主键   创建表格一定要创建主键

    联合唯一  (同时不能一样)

    create table t20(
    id int unique auto_increment,
    name char(12));

    通常写法为

    create table t20(
    id int primary key auto_increment,
    name char(12));

    create table t14(
    id int unique,
    ip char(15),
    port char(5),
    unique(ip,port));

    联合主键

    create table t14(
    id int unique,
    ip char(15),
    port char(5),
    primary key(ip,port));

    create table t14(
    id int unique,
    ip char(15) not null,
    port char(5) not null,
    unique(ip,port));

    删除表中的一行:delete  from  表名  where   id=1

    外键

    create table stu2(
    id int primary key auto_increment,
    name char(12) not null,
    gender enum('male','female') default 'male',
    class_id int,
    foreign key (class_id) references class(cid) on update cascade on delete cascade
    );

    级联修改  

    两张表     :  学生表  班级表

  • 相关阅读:
    为aptget设置http代理[转]
    tty&pty
    Overfencing
    ubuntu修改runlevel
    ls l文件类型[转]
    ubuntu文字界面与图形界面切换
    ubuntu没有/etc/inittab文件
    linux一些缩写的意思
    redhat server 5.4安装中文
    关闭linux警报
  • 原文地址:https://www.cnblogs.com/ch2020/p/12879180.html
Copyright © 2011-2022 走看看