DEFINITIONS

Definitions More Info.
Definition ID150
TitleSQL
CategoryMS_SCRIPT
DefinitionForeignKeyOverview
Definition Description/* This Transact-SQL scripts give a quick overview of all existing foreign key constraints with - parent table and column - parent key index - referenced table and column - update / delete action. Also the important information "IsNotTrusted" is returned. Works with SQL Server 2005 and higher version in all editions. Requires VIEW META DATA permissions. */ -- ForeignKeys Overview SELECT FK.name AS ForeignKeyName ,FK.delete_referential_action_desc AS DeleteAction ,FK.update_referential_action_desc AS UpdateAction ,FK.is_disabled AS IsDisabled ,FK.is_not_trusted AS IsNotTrusted ,IDX.name AS IndexName ,PARSCH.name + '.' + PAR.name AS ParentName ,PARCOL.name AS ParentColumn ,REFSCH.name + '.' + REF.name AS ReferenceName ,REFCOL.name AS ReferenceColumn FROM sys.foreign_keys AS FK INNER JOIN sys.foreign_key_columns AS FKC ON FK.object_id = FKC.constraint_object_id INNER JOIN sys.objects AS PAR ON FKC.parent_object_id = PAR.object_id INNER JOIN sys.schemas AS PARSCH ON PAR.schema_id = PARSCH.schema_id LEFT JOIN sys.indexes AS IDX ON FKC.parent_object_id = IDX.object_id AND FK.key_index_id = IDX.index_id INNER JOIN sys.columns AS PARCOL ON FKC.parent_object_id = PARCOL.object_id AND FKC.parent_column_id = PARCOL.column_id INNER JOIN sys.objects AS REF ON FKC.referenced_object_id = REF.object_id INNER JOIN sys.schemas AS REFSCH ON REF.schema_id = REFSCH.schema_id INNER JOIN sys.columns AS REFCOL ON FKC.referenced_object_id = REFCOL.object_id AND FKC.referenced_column_id = REFCOL.column_id ORDER BY ParentName ,ForeignKeyName ,ParentColumn ,ReferenceName ,ReferenceColumn;
RecordBycunay
Record Date21-02-2012 12:22:40
Düzenle
Kopyala
Sil