Unable To Drop A Mysql Table
I need to drop a deprecated, empty table from my MySQL Database. The table definition is noddy: CREATE TABLE IF NOT EXISTS `Address` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `Co
Solution 1:
SET FOREIGN_KEY_CHECKS =0;
DROPTABLE Address;
SET FOREIGN_KEY_CHECKS =1;
Solution 2:
To list foreign keys
selectconcat(table_name, '.', column_name) as 'foreign key',
concat(referenced_table_name, '.', referenced_column_name) as 'references'
from
information_schema.key_column_usage
where
referenced_table_name isnotnull;
For specifc search in your case:
select
constraint_name
from
information_schema.key_column_usage
where
referenced_table_name = 'Address' AND referenced_column_name = 'ContactId';
To drop a foreign key constraint:
ALTERTABLE [table_name] DROPFOREIGN KEY [constraint_name];
Post a Comment for "Unable To Drop A Mysql Table"