mysql Multiple Foreign Keys in a Table to the Same Primary Key

后端 未结 1 1700
时光说笑
时光说笑 2020-12-30 06:50

I have a table user with userID as the primary key. I have another table called Friends. In the Friends table, I have two

1条回答
  •  情话喂你
    2020-12-30 07:33

    No, you should create two foreign keys:

    ADD CONSTRAINT `ufd_users_fk` FOREIGN KEY (`userId`) 
      REFERENCES `users` (`userId`) 
      ON DELETE CASCADE ON UPDATE CASCADE,
    ADD CONSTRAINT `ufd_users_fk` FOREIGN KEY (`friendId`) 
      REFERENCES `users` (`userId`) 
      ON DELETE CASCADE ON UPDATE CASCADE;
    

    0 讨论(0)
提交回复
热议问题