为什么我对列设置了check约束,不起作用啊
create table teacher (
   tea_id                varchar(32)          not null,
   tea_name              char(10)             not null,
   tea_sex               char(4)              not null,
   tea_call              char(10)             null,
   tea_intro             varchar(255)         null,
   aca_id                varchar(32)          null,
   constraint PK_teacher primary key (tea_id)
)alter table teacher
   add constraint FK_teacher_REFERENCE_academy foreign key (aca_id)
      references academy (aca_id)alter table teacher add constraint ch_teacher check(tea_sex in ('男','女'))insert into teacher values('04064261130','李非','aaa','副教授','我是个教授',null)

解决方案 »

  1.   

    MYSQL的 CHECK 约束暂时只是注释作用。
      

  2.   

      tea_sex enum('男','女') not null,
      

  3.   

    create table teacher (
    tea_id                varchar(32)    not null,
    tea_name              char(10)       not null,
    tea_sex               enum('男','女') not null default '男',
    tea_call              char(10)   null,
    tea_intro             varchar(255)  null,
    aca_id                varchar(32)     null,
    constraint PK_teacher primary key (tea_id)
    ) engine innodb;insert into teacher values('0406423261130','李非','女','副教授','我是个教授',null)
      

  4.   

    create table teacher (
    tea_id                varchar(32)    not null,
    tea_name              char(10)       not null,
    tea_sex               char(2) not null ,
    tea_call              char(10)   null,
    tea_intro             varchar(255)  null,
    aca_id                varchar(32)     null,
    constraint PK_teacher primary key (tea_id)

    go
    alter table teacher add constraint ch_teacher check(tea_sex in ('男','女'))
    go
    insert into teacher values('0406423261130','李非','女','副教授','我是个教授',null)