Example:
First entity: Book(BookId - PK, Titlle)
Second entity (the weak entity): Chapter(No, Title)
(at this point Chapter.No
isn't a primary key because one or more books may have chapters with the same No
).
In order to create the weak table I would add BookId
to Chapter
table and, also, I would create a compound unique key and a simple PK:
create table dbo.Chapter(
Id int identity primary key,
BookId int not null referenced dbo.Book(BookId),
No tinyint not null,
unique(BoolId, No),
Title nvarchar(100) not null
);
The reasons for defining a simple PK for dbo.Chapter
are:
1) a compound PK could force me to define, also, compound FKs and
2) FK join elimination requires a simple FK.