Breaking News
Loading...
13/12/2013

Check all tables that have a reference to a table

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA='isporttl' AND COLUMN_NAME='userID'
AND TABLE_NAME <> 'user';

If we want to list the foreign keys to a specific table

SELECT CONSTRAINT_NAME, TABLE_NAME, REFERENCED_TABLE_NAME

FROM information_schema.REFERENTIAL_CONSTRAINTS

WHERE CONSTRAINT_SCHEMA = 'dbName'

AND REFERENCED_TABLE_NAME = 'tableName' 
If we want to list the tables that a specific table refer to
SELECT CONSTRAINT_NAME, TABLE_NAME, REFERENCED_TABLE_NAME
FROM information_schema.REFERENTIAL_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA = 'isporttl'
AND TABLE_NAME = 'userProgressSettings'

0 comments:

Post a Comment

 
Toggle Footer