首页 >数据库 >mysql教程 >mysql-数据库foreign key error 1215

mysql-数据库foreign key error 1215

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-06-06 09:33:42886浏览

mysql数据库

<code> 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);</code>

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

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn