MySQL之性别约束男、女


前言

对于课本上的check检查约束,在MySQL不支持使用,本人发现使用过程中其不会报错,但查看建表语句发现不存在check,网上查找资料发现

枚举enum字段类型

create table supplier_contact
(
    supplier_contact_id       varchar(11) not null comment '联系人id'
        primary key,
    supplier_contact_sex enum ('男','女') not null comment '联系人性别',
    supplier_contact_phone     varchar(20) not null comment '联系电话',
    supplier_contact_name varchar(10) not null comment '联系人名字',
    vend_id    int         not null comment '供应商id',
    foreign key (vend_id) references vendors(vend_id)
)
    comment '供应商联系人表' charset = utf8mb4;

不建议使用enum,除非能保证枚举范围只有像男、女这样不要改。


文章作者: Axieyun
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Axieyun !
评论
评论
  目录