码迷,mamicode.com
首页 > 数据库 > 详细

can't add foreign key in mysql?

时间:2014-07-16 21:36:29      阅读:374      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   art   for   re   

 1 create table department
 2     (dept_name        varchar(20), 
 3      building        varchar(15), 
 4      budget                numeric(12,2) check (budget > 0),
 5      primary key (dept_name)
 6     );
 7 
 8 create table course
 9     (course_id        varchar(8), 
10      title            varchar(50), 
11      dept_name        varchar(20),
12      credits        numeric(2,0) check (credits > 0),
13      primary key (course_id),
14      foreign key (dept_name) references department
15         on delete set null
16     );

显示出错can‘t add foreign key 。
版本:MySQL5.6
但在MySQL5.1上能运行
在网上各种找原因,都搞不定。最后是这样搞定的,太坑了:
 1 create table department
 2     (dept_name        varchar(20), 
 3      building        varchar(15), 
 4      budget                numeric(12,2) check (budget > 0),
 5      primary key (dept_name)
 6     );
 7 
 8 create table course
 9     (course_id        varchar(8), 
10      title            varchar(50), 
11      dept_name        varchar(20),
12      credits        numeric(2,0) check (credits > 0),
13      primary key (course_id),
14      foreign key (dept_name) references department(dept_name)
15         on delete set null
16     );

can't add foreign key in mysql?,布布扣,bubuko.com

can't add foreign key in mysql?

标签:style   blog   color   art   for   re   

原文地址:http://www.cnblogs.com/awater/p/3835811.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!