MS SQL запрос для нахождения связанных ключей в базе данных
SELECT TOP 100 PERCENT FK.COLUMN_NAME AS Field, PK.COLUMN_NAME AS Source, FK.TABLE_NAME AS FieldTab, PK.TABLE_NAME AS SourceTab
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE PK INNER JOIN
INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C ON PK.CONSTRAINT_CATALOG = C.UNIQUE_CONSTRAINT_CATALOG AND
PK.CONSTRAINT_SCHEMA = C.UNIQUE_CONSTRAINT_SCHEMA AND PK.CONSTRAINT_NAME = C.UNIQUE_CONSTRAINT_NAME INNER JOIN
INFORMATION_SCHEMA.KEY_COLUMN_USAGE FK ON C.CONSTRAINT_CATALOG = PK.CONSTRAINT_CATALOG AND
C.CONSTRAINT_SCHEMA = FK.CONSTRAINT_SCHEMA AND C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME AND
PK.ORDINAL_POSITION = FK.ORDINAL_POSITION
Комментариев нет:
Отправить комментарий