user997248
user997248

Reputation: 83

Weak entity in ER design

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

Answers (2)

reinierpost
reinierpost

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

  • if your primary key is really just id, you do not have a weak entity, but a strong entity;
  • if your primary key is id, whatever, and id is already unique by itself, then id by itself should be your primary key;
  • if your primary key is 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
    • if 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);
    • if id and whatever are both foreign keys, you do not have a weak entity, but a relationship;
    • if one of 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

nvogel
nvogel

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

Related Questions