Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

i tried to create tables as per given in my textbook in MySQL server as follows:

create table department
(dept_name      varchar(20), 
 building       varchar(15), 
 budget             numeric(12,2),
 primary key (dept_name)
);

create table course
(course_id      varchar(8), 
 title          varchar(50), 
 dept_name      varchar(20),
 credits        numeric(2,0),
 primary key (course_id),
 foreign key (dept_name) references department
);

the department table gets created, but an error

ERROR 1005 (HY000): Can't create table 'test.course' (errno: 150)

is displayed.

The queries seem very simple. And i am unable to find any mistake. What can be the possible error that is preventing me to create the table?

share|improve this question
    
Before posting question, do bit of googling and also please have a look at BASIC SQL Syntax –  Abdul Manaf Mar 31 at 5:36

1 Answer 1

up vote 0 down vote accepted

You are missing column name of parent table to which your child refer, while creating child table, do like below

create table department
(dept_name      varchar(20), 
 building       varchar(15), 
 budget             numeric(12,2),
 primary key (dept_name)
);

create table course
(course_id      varchar(8), 
 title          varchar(50), 
 dept_name      varchar(20),
 credits        numeric(2,0),
 primary key (course_id),
 foreign key (dept_name) references department(dept_name)
);
share|improve this answer
    
it worked. thanks a lot. –  user311726 Mar 31 at 5:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.