Foreign Key - ER Diagram Syntax

  • Type FK to mark a field as foreign key
  • To define a composite foreign key, use the table level FK() syntax
Order
-
OrderID int PK
CustomerID int FK > Customer.CustomerID
TotalAmount money NOT NULL
OrderStatusID int

(or)

Order
-
OrderID int PK
CustomerID int
TotalAmount money NOT NULL
OrderStatusID int
FK(CustomerID,OrderID) > OrderDetail(CustomerID,OrderID)

Relationships:

  • < one-to-many. e.g: Customer.id < Order.Id
  • > many-to-one. e.g: Order.Id > Customer.id
  • - one-to-one. e.g: Customer.id - Address.id
  • <> many-to-many. e.g: authors.id <> books.id

NOTE: All table names and column names are case sensitive. Ensure to use the same case during FK references