Put the FK in one of the two tables. Choose based on participation:
- One side is TOTAL → FK goes in the total-participation entity (Foreign Key approach, most common)
- Both TOTAL → Merge both entities into one table
- Both PARTIAL → Create a 3rd cross-reference table
Include relationship attributes in whichever table gets the FK.
FK goes in the N-side entity (the "many" side).
The FK references the PK of the 1-side entity.
Include relationship attributes in the N-side table.
Why N-side? Because putting FK on the 1-side would force multi-valued attributes (bad!).
New relationship table contains:
- FK → PK of Entity A
- FK → PK of Entity B
- Both FKs together = Composite PK
- All relationship attributes
Table contains:
- PK of owner entity (as FK)
- Partial key of weak entity
- Composite PK = {owner PK + partial key}
- All other attributes
New table contains:
- The multivalued attribute (as column)
- FK → PK of the entity that owns it
- Composite PK = {attribute + FK}
Every regular entity becomes its own table. Include all simple attributes. For composite attributes, include only the leaf-level simple parts (not the composite itself).
SSN,
Fname, Minit, Lname, ← from composite Name
Street, City, State, ← from composite Address
Salary, Bdate, Sex
)
Weak entities can't be identified alone — they need their owner. Their PK is always a composite key made of the owner's PK plus their own partial key.
Essn, ← FK to EMPLOYEE.SSN
Dependent_name, ← partial key
Sex, Bdate, Relationship
)
PK = {Essn, Dependent_name}
Most common ✓
FK goes in the TOTAL-participation entity.
DEPARTMENT(Dnumber, Dname, Mgr_ssn FK, Mgr_start_date)Department has total participation in MANAGES → gets the FK to Employee.
Both TOTAL
Merge both entities and the relationship into one single table.
Include all attributes from both + relationship attributes.
Choose either entity's PK as the combined PK.
Both PARTIAL
Create a 3rd relationship table with both FKs.
MANAGES(Essn FK, Dnumber FK, Start_date)PK = either FK (since it's 1:1, either is unique).
This is the most common relationship. The rule is simple: FK always goes in the entity on the N-side (many side). The FK references the PK of the 1-side entity.
One CUSTOMER row would need to store many order IDs → multi-valued → ILLEGAL in relational model.
If you put FK in the N-side:
Each ORDER row has exactly one customer ID → clean, atomic. ✓
ORDER(
OrderID,
OrderDate,
CustomerID ← FK to CUSTOMER
)
Many-to-many cannot be expressed with just two tables — you MUST create a third relationship table (junction/associative table).
PROJECT(Pnumber, Pname)
WORKS_ON(
Essn, ← FK to EMPLOYEE
Pno, ← FK to PROJECT
Hours ← relationship attribute
)
PK = {Essn, Pno}
A double-oval (multivalued attribute) like "Locations" of a department cannot be stored as a column. It violates 1NF. Always extract it into a new table.
DEPT_LOCATIONS(
Dnumber, ← FK to DEPARTMENT
Dlocation ← the multivalued attr
)
PK = {Dnumber, Dlocation}
When a diamond touches 3 or more entity rectangles, create a new relationship table. The PK is typically the combination of ALL foreign keys.
Sname, ← FK to SUPPLIER
PartNo, ← FK to PART
ProjName, ← FK to PROJECT
Quantity
)
PK = {Sname, PartNo, ProjName}
- Strong entity → its underlined attribute is PK
- Composite key in ER → combine those attributes as composite PK
- Weak entity → {owner's PK} + {partial key}
- M:N relationship table → {FK-A + FK-B} (both FKs combined)
- Multivalued attribute table → {attribute + entity FK}
- N-ary table → all FKs combined (usually)
- 1:1 merged table → either entity's PK (choose one)
- 1:1 cross-reference table → either FK (since 1:1, unique)
- FK references the PK of another table (must match)
- 1:1 (total one side) → FK in the total-participation entity
- 1:N → FK in the N-side (many side) entity
- M:N table → has TWO FKs, one to each entity
- Weak entity → FK is the owner's PK (also part of PK here)
- Multivalued table → FK is the owning entity's PK
- FK can be NULL only if participation is PARTIAL on that side
- Rename FK if needed to avoid naming conflicts (e.g., Essn, Dno)
Example: If EMPLOYEE has partial participation in MANAGES (not every employee manages), the FK Dept_managed in EMPLOYEE can be NULL for non-managers.
SSN, Name, ...,
Super_SSN ← FK to EMPLOYEE.SSN
)
FK references OWN table's PK. NULL for top-level.
COMPONENT(
Component_No, ← FK to ITEM
Item_No, ← FK to ITEM
Quantity
)
You have a superclass C with m subclasses {S1, S2, …, Sm}. Choose ONE of the four options based on the constraints shown in the diagram.
A category (UNION type) is when one subclass can belong to one of several different entity types. Example: OWNER can be a PERSON, BANK, or COMPANY — but not all at once.
Solution: Create a surrogate key — a new artificial identifier for the category table.
Each superclass entity gets the surrogate key added as a FK (to link back to the category).
BANK(BankCode, Name, OwnerID FK)
COMPANY(CompNo, Name, OwnerID FK)
OWNER(OwnerID, Address)
← surrogate key! own new PK
col1 INT NOT NULL,
col2 VARCHAR(50) NOT NULL,
col3 DATE,
PRIMARY KEY (col1)
);
OrderID INT NOT NULL,
CustID INT,
PRIMARY KEY (OrderID),
FOREIGN KEY (CustID)
REFERENCES Customer(CustID)
ON DELETE CASCADE
ON UPDATE CASCADE
);
Essn CHAR(9) NOT NULL,
Pno INT NOT NULL,
Hours DECIMAL(3,1),
PRIMARY KEY (Essn, Pno),
FOREIGN KEY (Essn)
REFERENCES EMPLOYEE(SSN),
FOREIGN KEY (Pno)
REFERENCES PROJECT(Pnumber)
);
NOT NULLColumn must have a valueUNIQUENo duplicate values (candidate key)DEFAULT valValue if none providedON DELETE CASCADEDelete child rows when parent deletedON DELETE SET NULLSet FK to NULL when parent deletedON DELETE RESTRICTReject deletion if child rows existCHECK (condition)Enforce a custom rule on valuesALTER TABLE T ADD col INT;
-- Modify a column
ALTER TABLE T MODIFY col VARCHAR(100);
-- Drop a column
ALTER TABLE T DROP COLUMN col;
-- Drop entire table
DROP TABLE T;
-- Clear all rows, keep table
TRUNCATE TABLE T;
Given: EMPLOYEE, DEPARTMENT, PROJECT, DEPENDENT entities with WORKS_FOR (1:N), MANAGES (1:1), WORKS_ON (M:N), CONTROLS (1:N), SUPERVISION (1:N unary), DEPENDENTS_OF (weak) relationships.
DEPARTMENT(Dnumber, Dname)
PROJECT(Pnumber, Pname, Plocation)
Essn, ← FK → EMPLOYEE.SSN
Dep_name, ← partial key
Sex, Bdate, Relationship
)
PK = {Essn, Dep_name}
→ FK goes in DEPARTMENT
DEPARTMENT(Dnumber, Dname,
Mgr_ssn, ← FK→EMPLOYEE.SSN
Mgr_start_date)
EMPLOYEE(..., Dno)
← FK → DEPARTMENT.Dnumber
PROJECT(..., Dnum)
← FK → DEPARTMENT.Dnumber
EMPLOYEE(...,
Super_ssn)
← FK → EMPLOYEE.SSN
NULL for top-level supervisors
WORKS_ON(
Essn, ← FK→EMPLOYEE.SSN
Pno, ← FK→PROJECT.Pnumber
Hours
)
PK = {Essn, Pno}
DEPT_LOCATIONS(
Dnumber, ← FK→DEPT
Dlocation
)
PK = {Dnumber, Dlocation}
DEPARTMENT(Dnumber, Dname, Mgr_ssn, Mgr_start_date)
PROJECT(Pnumber, Pname, Plocation, Dnum)
DEPENDENT(Essn, Dep_name, Sex, Bdate, Relationship)
WORKS_ON(Essn, Pno, Hours)
DEPT_LOCATIONS(Dnumber, Dlocation)
- Strong entity → table with all simple attributes
- Composite attribute expanded into simple parts
- Derived attribute skipped (not stored)
- Multivalued attribute gets its OWN table (Step 6)
- Weak entity → combined PK with owner's PK
- 1:1 → FK approach (total side gets FK)
- 1:N → FK in N-side entity
- M:N → new relationship table, composite PK
- N-ary → new table, all entity PKs as FKs
- Unary 1:N → self-referencing FK same table
- Unary M:N → new table, two FKs to same entity
- Relationship attributes included correctly
- Every table has a Primary Key defined
- All FKs reference existing PKs
- Total participation → NOT NULL on that FK
- Partial participation → FK can be NULL
- EER hierarchy mapped with correct option (8A/B/C/D)
- Union type has surrogate key if PKs differ