i have a "main table", call it Customers
:
CREATE TABLE Customers (
CustomerID int PRIMARY KEY NOT NULL,
FirstName nvarchar(50),
LastName nvarchar(50)
)
And i have a "satellite table", call it Customer_IllegallyObtainedInformation
:
CREATE TABLE Customer_IllegallyObtainedInformation (
CustomerID int PRIMARY KEY NOT NULL,
CellPhonePin int,
SexualOrientation varchar(20),
EmailPassword varchar(50)
)
Now, what i want is a foreign key constraint from the Illegal
table back to the main Customers
table:
In other words:
- there can be a
Customer
without anIllegal
entry - but there can never be an
Illegal
entry without aCustomer
My instinct was to, in the SQL Server database diagram, drag
- FROM the
Illegal
table TO theCustomers
table
Indicating to SQL Server that Customers_IllegallyObtainedInformation
is the "child" in the relationship. Instead what happens in that SQL Server makes it a one-to-one relationship:
Meaning that if you try to insert a Customer
, it will fail because there is no existing Illegal
information.
How can i create a "Parent-Child", or "One-to-Optional-One" relationship in SQL Server?
Note: Don't confuse the example with the question. i could create an sacrificial primary surrogate key in the Illegal
table:
But that wasn't my question.