Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2 foreign keys referencing same table

Can I have two foreign keys in the same table that are referencing an other table named profil(same one) ?

my table is MailSent, it contains : primary key (Id), date, foreignkey1 (profil_sender), foreignkey2 (profil_receiver)

like image 424
Najoua Avatar asked Nov 03 '16 11:11

Najoua


1 Answers

Add foreign keys (profil_sender_id, profil_receiver_id) to an existing table (MailSent), follow the following steps:

ALTER TABLE MailSent ADD CONSTRAINT fk_profile_sender_id FOREIGN KEY (profil_sender_id) REFERENCES TABLE-NAME(id);

ALTER TABLE MailSent ADD CONSTRAINT fk_profil_receiver_id FOREIGN KEY (profil_receiver_id) REFERENCES TABLE-NAME(id);
like image 193
Rimon Khan Avatar answered Oct 08 '22 18:10

Rimon Khan