How to use the keyword 'references' in MySQL?

后端 未结 5 991
庸人自扰
庸人自扰 2020-12-13 19:08

How is the references keyword used when creating a table?

Let\'s say I want to create two tables person and hobby and I want t

5条回答
  •  囚心锁ツ
    2020-12-13 19:29

    Create the hobby table similarly to this:

    CREATE TABLE hobby (
      id INT NOT NULL AUTO_INCREMENT,
      person_id INT NOT NULL,
      hobby_name VARCHAR(255),
      PRIMARY KEY(id),
      FOREIGN KEY(person_id) REFERENCES person(id))
    

提交回复
热议问题