MySQL Error number: 3193; Symbol: ER_TABLE_REFERENCED; SQLSTATE: HY000

文档解释

Error number: 3193; Symbol: ER_TABLE_REFERENCED; SQLSTATE: HY000

Message: Cannot complete the operation because table is referenced by another connection.

Error 3193 (ER_TABLE_REFERENCED): Table ‘%s’ is being referenced and can’t be dropped

Error 3193 occurs when MySQL is trying to delete a table that has another table pointing to it. The server won’t be able to complete the request because the referenced table can’t be dropped. This prevents unintentional data loss.

Common cases involving this error involve scenarios like:

Trying to drop a table that is mentioned in a view

Trying to drop a table mentioned in a stored procedure

Trying to drop a table used in a foreign key constraint with the RESTRICT option

The solution to this error is to track down any references to the table in question and remove them before attempting to drop the table. You’ll need to perform a query to find any references that might be pointing to the table:

SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE table_name = ‘table_name_you_are_trying_to_drop’;

This query will return any tables that are pointing to the table you’re trying to drop. Once you have identified the references, you can either remove the references or drop the referenced tables before dropping the original table.

Note that if you are using the CASCADE clause on the DROP TABLE command, this should take care of any references to the dropped table.

你可能感兴趣的