Some entities cannot be told apart by their own attributes. Two exams both have a "question 3":
question
| exam_id | question_no | body | points |
|---|---|---|---|
| A | 1 | Define a tuple. | 2 |
| A | 3 | Write the SQL for σ. | 5 |
| B | 3 | Name the 6 basic operators. | 4 |
question is a :
- it has no key of its own,
- it depends on an owner (identifying) entity set, here
exam, through an identifying relationship, - its partial key (discriminator), here
question_no, tells apart the weak entities of one owner, - its participation in the identifying relationship is total: every question belongs to an exam.
In an ER diagram, a weak entity set and its identifying relationship have double borders. The partial key has a dashed underline.
As a table
sql
CREATE TABLE question (
exam_id integer REFERENCES exam (exam_id) ON DELETE CASCADE,
question_no integer,
body text,
points integer,
PRIMARY KEY (exam_id, question_no)
);- Primary key: the owner's key plus the partial key.
- The owner's key is also a foreign key.
ON DELETE CASCADE(Chapter 5): a weak entity cannot exist without its owner.