如果我的问题看起来陈词滥调,我真的不太喜欢编程。每当我尝试这个程序时,我得到“错误代码:1215:无法添加外键约束MYSql”
create table department(dept_name varchar(20) primary key,
building varchar(15),
budget numeric(12,2));
create table course(course_id varchar (7),
title varchar (50),
dept_name varchar (20),
credits numeric (2,0),
primary key (course_id),
foreign key (dept_name) references department);
有人可以帮助我
答案 0 :(得分:0)
您尚未定义要引用的dept_name
列。请试试这个:
create table department(dept_name varchar(20) primary key,
building varchar(15),
budget numeric(12,2));
create table course(course_id varchar (7),
title varchar (50),
dept_name varchar (20),
credits numeric (2,0),
primary key (course_id),
foreign key (dept_name) references department(dept_name));