Defining a one-to-one relationship in SQL Server Defining a one-to-one relationship in SQL Server sql-server sql-server

Defining a one-to-one relationship in SQL Server


One-to-one is actually frequently used in super-type/subtype relationship. In the child table, the primary key also serves as the foreign key to the parent table. Here is an example:

org_model_00

CREATE TABLE Organization(      ID       int PRIMARY KEY,     Name     varchar(200),     Address  varchar(200),     Phone    varchar(12))GOCREATE TABLE Customer(      ID              int PRIMARY KEY,     AccountManager  varchar(100))GOALTER TABLE Customer    ADD  FOREIGN KEY (ID) REFERENCES Organization(ID)        ON DELETE CASCADE        ON UPDATE CASCADEGO


Why not make the foreign key of each table unique?


there is no such thing as an explicit one-to-one relationship.

But, by the fact that tbl1.id and tbl2.id are primary keys and tbl2.id is a foreign key referenceing tbl1.id, you have created an implicit 1:0..1 relationship.