How to add Foreign Key in existing table
if you want to add any column as a foreign key in your existing table then you have to write following MySQL query for that
Syntax:
ALTER TABLE tablename ADD CONSTRAINT FOREIGN KEY column_name REFERENCES ref_table_name(column_name)
if you want to add multiple column as a foreign key in the same table then you have to write the following MySQL query:
Syntax:
ALTER TABLE tablename ADD CONSTRAINT FOREIGN KEY column_name REFERENCES ref_table_name(column_name) ADD CONSTRAINT FOREIGN KEY column_name REFERENCES ref_table_name(column_name) ADD CONSTRAINT FOREIGN KEY column_name REFERENCES ref_table_name(column_name)
No comments:
Post a Comment