en Peris
en Peris

Reputation: 1717

Cannot drop index {index_name}: needed in a foreign key constraint

I want to drop an index, but I can't because is used in another table, but I can't find where

ALTER TABLE t_course DROP INDEX user_id

Is there a way to know where it is used ?

Upvotes: 0

Views: 2268

Answers (1)

dustytrash
dustytrash

Reputation: 1590

To find the other table that the constraints reference:

select COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_COLUMN_NAME, REFERENCED_TABLE_NAME
from information_schema.KEY_COLUMN_USAGE
where TABLE_NAME = 't_course';

Take a look at the REFERENCED_TABLE_NAME returned from the above query.

Upvotes: 2

Related Questions