MySQL中使用外键[FOREIGN KEY]

SQL语言:

CREATE TABLE Class (
Class_ID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(255)
) type=innodb;

CREATE TABLE Student(
Student_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(255),
c_ID INT UNSIGNED NOT NULL,
FOREIGN KEY(c_ID) REFERENCES Class(Class_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
);

逻辑图:
image

This entry was posted in 其他技术 and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>