• mysql 8.0版本中添加表级约束外键失败原因之一


     1 create table if not exists t_classes(
     2     classes_id int(3),
     3     classes_name varchar(40),
     4     constraint pk_classes_id primary key(classes_id)
     5 );
     6 
     7 -- 利用标记约束添加主键和外键
     8 create table if not exists t_student(
     9     student_id       int(10),
    10     student_name     varchar(20),
    11     sex           char(2),
    12     birthday      date,
    13     email         varchar(30),
    14     classes_id    int(3),
    15     constraint    fk_classes_id foreign key (classes_id) references t_classes (classes_id),
    16     constraint    student_id_pk primary key(student_id) 
    17 );

    create table if not exists t_student(
        student_id       int(10)  primary key,
        student_name     varchar(20),
        sex           char(2),
        birthday      DATE,
        email         varchar(30),
        classes_id2    int(3), 
    --         这里的添加顺序是先添加主键后添加外键,会失败,提示语法错误
        constraint    student_id_pk primary key(student_id)     
        constraint    fk_classes_id foreign key (classes_id2) references t_classes (classes_id)  
    );

    同样是添加主键和外键,顺序颠倒后会报语法错误

    数据库版本号:8.0.19

  • 相关阅读:
    HTML5---offline application(application cache)
    apache asp.net
    长轮询
    comet ajax轮询
    bootstrap3
    weixin
    backbone csdn
    backbone case
    backbone showcase
    javascript performance
  • 原文地址:https://www.cnblogs.com/zhipeng-wang/p/13044881.html
Copyright © 2020-2023  润新知