Hoje vou mostrar a vocês mais um script que uso para fins de documentação de ambientes. Uma consulta que mostra as chaves estrangeiras e relacionamentos de todas as tabelas do seu banco de dados.
Para obter essa informação basta executar o seguinte script:
SELECT ForeignKeys.NAME [ForeignKeyName], PrimaryKeyTable.NAME [PrimaryTableName], PrimaryKeyColumn.NAME [PrimaryColumnName], ForeignKeyTable.NAME [ReferenceTableName], ForeignKeyColumn.NAME [ReferenceColumnName], ForeignKeys.update_referential_action_desc [UpdateAction], ForeignKeys.delete_referential_action_desc [DeleteAction] FROM sys.foreign_keys ForeignKeys JOIN sys.foreign_key_columns ForeignKeyRelationships ON ( ForeignKeys.object_id = ForeignKeyRelationships.constraint_object_id ) JOIN sys.tables ForeignKeyTable ON ForeignKeyRelationships.parent_object_id = ForeignKeyTable.object_id JOIN sys.columns ForeignKeyColumn ON ( ForeignKeyTable.object_id = ForeignKeyColumn.object_id AND ForeignKeyRelationships.parent_column_id = ForeignKeyColumn.column_id ) JOIN sys.tables PrimaryKeyTable ON ForeignKeyRelationships.referenced_object_id = PrimaryKeyTable.object_id JOIN sys.columns PrimaryKeyColumn ON ( PrimaryKeyTable.object_id = PrimaryKeyColumn.object_id AND ForeignKeyRelationships.referenced_column_id = PrimaryKeyColumn.column_id ) ORDER BY ForeignKeys.NAME
Como vocês podem ver na primeira coluna está o nome da chave estrangeira, na segunda coluna o nome da tabela primária, na terceira coluna o nome da coluna na tabela primária, na quarta coluna o nome da tabela referenciada e na quinta coluna o nome da coluna na tabela referenciada.
Uma informação importante é, saber se esses relacionamentos sofrem alguma ação de integridade referencial em cascata e saber quais ações são essas.
Port video games have actually long been a popular type of entertainment, providing exhilarating gameplay…
When it pertains to online gambling, safety needs to be a top issue for every…
There are many reasons to play no-cost online casino games in the coming year. The…
On the internet casinos have acquired tremendous appeal in recent times, offering gamers with the…
Welcome to our useful post concerning the very best casino site game! Whether you're a…
The random number generator (or RNG) is the program that generates the outcome of every…