Tuesday, April 24, 2007

How to know what table is linking to the row you are trying to delete

You are trying to delete a row in a table but b/c of the db constraint you can't, here how to find out what table is causing the issue.

In oracle you would get an error like this:
ORA-02292: integrity constraint (TESTDB.FK_REF_114571) violated - child record found

select * from user_constraints where constraint_name = 'FK_REF_114571'


In MSSQL
select * from INFORMATION_SCHEMA.constraint_column_usage
where constraint_name = 'FK_REF_114571'