EX0006 : Identify possible missing Foreign Keys |
The topic describes the EX0006 analysis rule.
Identify possible missing Foreign Keys
The rule checks database tables for columns which do not have a foreign key reference, but match by name pattern and data type to a primary key of a different table.
For example:
-
When using pattern ‘{column_name}’:
The rule will match and suggest adding foreign key to [Sales].[SalesOrderDetailPartitioned].[SpecialOfferID] referencing [Sales].[SalesOrderDetailPartitioned].[SpecialOfferID].
-
When using pattern ‘{table_name}{column_name}’:
The rule will match and suggest adding foreign key to dbo.[Sale].[CustomerID] referencing dbo.[Customer].[ID].
-
When using pattern ‘FK_{table_name}_{column_name}’:
The rule will match and suggest adding foreign key to dbo.[Sale].[ID] referencing dbo.[Customer].[FK_Sale_ID].
The rule has a ContextOnly scope and is applied only on current server and database schema.
Name | Description | Default Value |
---|---|---|
ForeignKeyColumnNamePattern |
Foreign key column name pattern. |
{column_name} |
ForeignKeyNamePattern |
Foreign key constraint name pattern. |
regexp:FK_[A-Z][A-Za-z_]+ |
The rule requires Analysis Context. If context is missing, the rule will be skipped during analysis.
Design Rules, Explicit Rules, Code Smells
There is no additional info for this rule.