Skip to main content

How to insert foreign key on column when data is present in table

 SET FOREIGN_KEY_CHECKS=0;

ALTER TABLE <TABLE_NAME> ADD FOREIGN KEY (COLUMN_NAME) REFERENCES TABLE_NAME(id)

Eg - Alter table vivagame11.matches add foreign key (leagueid) references vivagame11.league(id)

Comments