I have read Database system concepts, 6th edition, Silberschatz. I\'m going to implement the university database system shown in chapter 2 on OS X
The syntax of FOREIGN KEY
for CREATE TABLE
is structured as follows:
FOREIGN KEY (index_col_name)
REFERENCES table_name (index_col_name,...)
So your MySQL DDL should be:
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)
);
Also, in the department
table dept_name
should be VARCHAR(20)
More information can be found in the MySQL documentation