Reputation: 83
I have a weak entity and it has an id
as its primary key and also has another attribute (author_id
) which has to refer to another entity's (Author
's) primary key.
So my question is this: can a weak entity have a composite key (id, author_id
)?
Upvotes: 0
Views: 2100
Reputation: 8591
A weak entity is an entity with a primary key that contains at least one of its foreign keys, but that doesn't contain only foreign keys. This is not possible with only one attribute. So
id
, you do not have a weak entity, but a strong entity;id
, whatever
, and id
is already unique by itself, then id
by itself should be your primary key;id
, whatever
, and neither id
nor whatever
are not unique by themselves, but id
, whatever
together are unique, then they are a legitimate primary key, and
id
, whatever
are a foreign key together, you do not have a weak entity, but a subentity (the foreign key is an IS-A relationship);id
and whatever
are both foreign keys, you do not have a weak entity, but a relationship;id
and whatever
is a foreign key and the other is not, you have a weak entity.All of these cases may occur. It depends on what you want to model and which information you have about it.
Upvotes: 0
Reputation: 25526
If Id is a key then (Id, Authorid) can't possibly be a key in the same table. No key is ever a subset of another because keys by definition should be irreducibly unique.
The answer to your question is yes. A weak entity may have a composite key.
Upvotes: 1