90 likes | 152 Views
Summary on Translating ER Diagra ms. A may not do B No minimum requirement A should do B at least once Minimum requirement: 1 A can do B many times No upper limit A can do B at most once Upper limit: 1 A does B exactly once A does B 1 or more times A does B 0, 1, or more times
E N D
A may not do B • No minimum requirement • A should do B at least once • Minimum requirement: 1 • A can do B many times • No upper limit • A can do B at most once • Upper limit: 1 • A does B exactly once • A does B 1 or more times • A does B 0, 1, or more times • A does B 0 or 1 times Does B A Does B A Does B A Does B A Does B A Does B A
To judge if an entity B is a weak entity • First, the relationship must have the following two constraints: • Second, B’s key (bid) alone cannot serve as a primary key for the entity set B, e.g., • payment-number (of loan) • section-number (of course) • dependent-name (of employee) bid aid Does B A
Many to Many • Create three tables • A (primary key: (aid)) • B (primary key: (bid)) • Does (primary key: (aid, bid); foreign key: (aid), (bid)) • Same, but the total participation constraint of A is not captured • Same, but the total participation constraint of B is not captured • Same, but both total participation constraints are not captured bid aid Does B A bid aid Does B A bid aid Does B A bid aid Does B A
bid • One to Many • Create two tables (tables B and Does combined into Does_B) • A (primary key: (aid)) • Does_B (primary key:(bid); foreign key:(aid)) • Same, but the total participation constraint of A is not captured • Same, also in Does_B: aid … NOT NULL • Same, also in Does_B: aid … NOT NULLthe total participation constraint of A is not captured aid Does B A bid aid Does B A bid aid Does B A bid aid Does B A
bid aid • One to One • Create two tables • A (primary key: (aid)) • Does_B (primary key: (bid); foreign key: (aid);unique: (aid)) • Or, • A_Does (primary key: aid; foreign key: (bid);unique: (bid)) • B (primary key: (bid)) Does B A
bid aid • One to One (cont.) • Create two tables • A (primary key: (aid)) • Does_B (primary key: (bid); foreign key: (aid);unique: (aid);aid … NOT NULL) • A_Does (primary key: (aid); foreign key: (bid);unique: (bid);bid … NOT NULL) • B (primary key: (bid)) Does B A bid aid Does B A
One to One (cont.) • Create two tables • A_Does_B (primary key: (aid); unique: (bid);bid … NOT NULL) bid aid Does B A Combine into a single table. This is suggested by a student in the class!!!
Weak Entity • Create two tables • A (primary key: aid) • Does_B (primary key: (aid, bid); foreign key: (aid);aid … NOT NULL;ON DELETE CASCADE) bid aid Does B A This is optional since primary key already implies aid must be NOT NULL.