建约束

    技术2022-05-11  6

    创建约束

    alter table 表名

    add constraint 约束名 约束类型(具体约束类型)

     

    删除约束

    alter table 表名

    drop constraint 约束名

     

    主键约束

    alter table student

    add constraint PK_id primary key(id)

     

    外建约束(主表student 从表stuinfo 关联字段stuNo)

    alter table stuinfo(从表)--(外键)

    add constraint FK_stuNo forign key(stuNo) references student (stuNo) (主表)--(主键)  

     

    唯一约束

    alter table student

    add constraint UQ_usercode unique(usercode)

     

    添加默认约束

    alter table student

    add constraint DF_address default('地址不详') for address

     

    检查约束

    alter table student

    add constraint CK_age check(age>18)   


    最新回复(0)