EX0006 : Identify possible missing Foreign Keys

The topic describes the EX0006 analysis rule.

Message

Identify possible missing Foreign Keys

Description

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].

How to fix

Scope

The rule has a ContextOnly scope and is applied only on current server and database schema.

Parameters
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_]+

Remarks

The rule requires Analysis Context. If context is missing, the rule will be skipped during analysis.

Effort To Fix
1 hour per issue.
Categories

Design Rules, Explicit Rules, Code Smells

Additional Information

There is no additional info for this rule.

See Also

Other Resources