Get Adobe Flash player

Primary Key and Foreign Keys Naming Standard

Primary Key

Simple Name:   <Table Name> + PrimaryKey
Example:  ClientPrimaryKey

Alternate Name:  <Table Name> + pk 
Example:  ClientPk  or Client_pk

Primary keys in most database systems have two functions:  1) Insures the data must is unique.  and 2) an index is also created.   

 

Foreign Keys

A foreign Key is the database engine’s way of maintaining proper data relationship between the parent and child table.    For example, lets say we have two tables.  Order and OrderDetail.   The relationship is that there is 1 record in the parent (Order) and many records in the child (OrderDetail).  

Simple Name:  <Table Name> + ForeignKey + sequence
Example:  OrderDetailForeignKey1,  OrderDetailForeignKey2

Alternate Name: <Table Name> + fk + sequence
Example:  OrderDetailFk1,  OrderDetailFk2 or OrderDetail_fk3

NOTE:  with the creation of a Foreign Key, the underlying index is not created.   You must also create a index.

 

Syntax (will work with all database engines):
ALTER TABLE OrderDetail

ADD OrderDetailForeignKey1

FOREIGN KEY (OrderID)

REFERENCES Order (OrderID);

 

CREATE INDEX OrderDetaiIindex1 on Order (OrderID)