![]() ![]() Suppose you have an employee table in the database, and there is a column that references the foreign key of another table, say orders. Once a MySQL Foreign Key is created on a table, you may want to remove the foreign key from that table then, we need to implement the ALTER TABLE query:.Also, if the clauses – ON DELETE and ON UPDATE are not specified, then MySQL’s default action will be RESTRICT option.Whereas, only three actions as: SET NULL | RESTRICT | CASCADE, are entirely supported by MySQL. Here, the ref_option denotes five reference options in MySQL as: SET DEFAULT | RESTRICT | SET NULL |CASCADE | NO ACTION.REFERENCES TableName (Column1, Column2, …) Here is a vital syntax that defines a foreign key constraint using the statements CREATE TABLE or ALTER TABLE shown below:ĬONSTRAINT (symbol) FOREIGN KEY IndexName (Column1, Column2, ….).Thus, we state the foreign key on the child table. The relationship of the foreign key contains a parent table with initial column values and a child table with column values that reference the parent table column values. Additionally, foreign key constraints ensure the consistency of the related data. MySQL supports foreign keys, which enable the cross-referencing of associated data across tables.Provide the table name here to view the result.Īfter dropping the Foreign Key, you can ensure this by viewing the structure of that table: SHOW CREATE TABLE TableName How to Drop Foreign Key in MySQL? You can obtain the created constraint name of the particular table by the following command: SHOW CREATE TABLE TableName ![]() This constraint name defines the name of the foreign key specified constraint added while creating the table. Next, we must state the constraint name after the keywords drop the foreign key in the above syntax. After this ALTER TABLE keywords, we will specify the table name from which the foreign key will be dropped. The statement ALTER TABLE is used for the Drop Foreign Key query so that the foreign key created in the table can be modified, and the table will be updated. Let’s explain the terms in the syntax as follows: ALTER TABLE TableName DROP FOREIGN KEY ConstraintName ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |