FOREIGN KEY MULTI FIELD HELP!
I have 2 table
TABLE CLASS
(
school varchar(50),
year varchar(50),
grade varchar(50),
className varchar(50),
PRIMARY KEY (school,year,grade,className)
)
TABLE STUDENT
(
student_id varchar(50) PRIMARY KEY,
detail varchar(50)
)
Now, I want to subclass for students. How t开发者_如何学Co create a reference?
Just do what everyone else does...
CREATE TABLE CLASS (
id int not null auto_increment PRIMARY KEY, -- CREATE A KEY COLUMN
school varchar(50),
year varchar(50),
grade varchar(50),
className varchar(50),
unique (school,year,grade,className)
);
CREATE TABLE STUDENT (
student_id varchar(50) PRIMARY KEY,
class_id int references class, -- REFERENCE THE KEY
detail varchar(50)
);
精彩评论