I have a TestPack table that can have n no of Lines associated with it. But a Line may exist without a TestPack. Later on, a Line might be assigned a TestPack#.
What this relationship is called and how do I implement this relationship in SQL Server 2008?
Best How To :
It's called a "one-to-zero-or-one" relationship, as one Line might be associated to zero or one TestPacks.
You can implement it by using a FK that allows NULL values.
CREATE TABLE TestPack (id INT,
PRIMARY KEY (id))
CREATE TABLE Line (id INT,
TestPackId INT NULL,
FOREIGN KEY (TestPackId) REFERENCES TestPack(id))
By making the "TestPackId" column in "Line" table to allow NULL values, you can have a Line with no TestPack (inserting a NULL there), and then assiging a TestPack by setting the id of the corresponding TestPack later.