How to establish Foreign key constraints in mysql
Editor to share with you mysql how to establish foreign key constraints, I hope you will learn a lot after reading this article, let's discuss it together!
Mysql's method of establishing foreign key constraints: directly execute [CREATE TABLE stu (sid INT PRIMARY KEY,NAME VARCHAR (50) NOT NULL);] statement.
Add a foreign key constraint
CREATE TABLE stu (sid INT PRIMARY KEY, NAME VARCHAR (50) NOT NULL)
Add foreign key constraint mode 1
CREATE TABLE score1 (score DOUBLE, sid INT, CONSTRAINT fk_stu_score1_sid FOREIGN KEY (sid) REFERENCES stu (sid))
Add foreign key constraint mode 2 (this can be used if the table already exists)
CREATE TABLE score1 (score DOUBLE, sid INT); ALTER TABLE score1 ADD CONSTRAINT fk_sid FOREIGN KEY (sid) REFERENCES stu (sid) has finished reading this article. I believe you have some understanding of how to establish foreign key constraints in mysql. You want to know more about it. Welcome to follow the industry information channel. Thank you for reading!