欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

mysql-数据库foreign key error 1215

程序员文章站 2022-05-14 15:39:39
...
mysql数据库
 create table department(dept_name varchar(20) not null primary key, building varchar(20),budget numeric(12,2)); create table instructor( ID varchar(5),  name varchar(20),  dept_name varchar(20),  salary numeric(12,1));create table course( course_id varchar(8),  title     varchar(50),  dept_name varchar(20) references department,  credits   numeric(2,0),  primary key (course_id)  #foreign key constraints can be here too :    #foreign key (dept_name) references department);/*alter table course   change column course_id     course_id varchar(8) unique;*/create table section( course_id     varchar(8),  sec_id        varchar(8),  semster       varchar(6),  year          numeric(4,0),  building      varchar(15),  room_number   varchar(7),  time_sloth_id varchar(4),  primary key(course_id,semster,year),  foreign key (course_id) references course);create table teach( ID          varchar(5),  course_id   varchar(8),  semster     varchar(6),  year        numeric(4,0),  primary key (ID,course_id,semster, year),  foreign key (ID) references instructor,  foreign key (course_id, semster, year) references section);

这段代码运行在MySql上总是在create table section的时候报error 1215,不能添加外键......求问为什么啊......

相关标签: mysql 数据库