How to check foreign keys related to a table
Firstly, find out your FOREIGN KEY
constraint name in this way:
SELECT
TABLE_NAME,
COLUMN_NAME,
CONSTRAINT_NAME, -- <<-- the one you want!
REFERENCED_TABLE_NAME,
REFERENCED_COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE
REFERENCED_TABLE_NAME = 'My_Table';
You can also add (to the WHERE
clause) if you have more than one table called My_Table
in different schemas.
AND TABLE_SCHEMA = 'My_Database';
And then you can remove the named constraint in the following way:
ALTER TABLE My_Table DROP FOREIGN KEY My_Table_Constraint;
References: 1 & 2.
Editied the Query above. Changed Referenced Table name to Table Name as Referenced Table name is the table which is being referenced and hence the result of the original query wont show you the foreign keys on your table.
SELECT
TABLE_NAME,
COLUMN_NAME,
CONSTRAINT_NAME, -- <<-- the one you want!
REFERENCED_TABLE_NAME,
REFERENCED_COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE
Table_name = 'case_qualitycontrolcase' and constraint_name = f