Reputation: 668
CREATE DATABASE H;
USE H;
CREATE TABLE stu(
sid CHAR(10),
sname CHAR(10)
);
CREATE TABLE Enrolled(
sid CHAR(10),
studid CHAR(20),
cid CHAR(20),
grade CHAR(10),
PRIMARY KEY (cid),
FOREIGN KEY(sid) REFERENCES stu(sid)
);
the error 1215 is presented.
Wanna know what's wrong about the source code.
Might there be some fundamental mistake about the usage of foreign key referencing.
Could anybody help to solve the problem? Will be really thankful for your kind answer;)
Upvotes: 0
Views: 4514
Reputation: 263893
You need to reference a column that a key defined on it,
CREATE TABLE stu
(
sid CHAR(10) PRIMARY KEY,
sname CHAR(10)
);
Upvotes: 5