ER Diagram Notation
Basic ER Components
Rectangle
Represents an Entity Type
Use for: Regular/Strong entities that exist independently
Examples from slides:
EMPLOYEE, DEPARTMENT, PROJECT, STUDENT, COURSE
Oval/Ellipse
Represents an Attribute
Use for: Simple, atomic attributes
Examples:
Name, SSN, Salary, Address, Age
Diamond
Represents a Relationship Type
Use for: Associations between entities
Examples:
WORKS_FOR, MANAGES, WORKS_ON, ENROLLS
Double Rectangle
Represents a Weak Entity Type
Use for: Entities that depend on another entity for existence
Example from slides:
DEPENDENT (depends on EMPLOYEE)
Double Diamond
Represents an Identifying Relationship
Use for: Relationships that help identify weak entities
Example:
DEPENDENTS_OF (identifying relationship for DEPENDENT)
Double Oval
Represents a Multivalued Attribute
Use for: Attributes that can have multiple values
Examples from slides:
{Locations} for DEPARTMENT, {Degrees} for PERSON, {Colors} for CAR
Dashed Oval
Represents a Derived Attribute
Use for: Attributes calculated from other attributes
Example from slides:
Age (derived from BirthDate), Number_of_employees (derived by counting)
Underlined Attribute
Represents a Key Attribute
Use for: Attributes that uniquely identify entities
Examples:
SSN (EMPLOYEE), Dnumber (DEPARTMENT), StudentID
Dashed Underlined Oval
Represents a Partial Key (for weak entities)
Use for: Discriminator of weak entity (part of its identification)
Example:
Dependent_name in DEPENDENT entity
Participation & Cardinality Constraints
―――
Single Line
Represents Partial Participation
Use when: Not all entities must participate (min = 0)
Example:
Some courses may have no enrollments
═══
Double Line
Represents Total Participation
Use when: Every entity must participate (min = 1)
Example from slides:
Every EMPLOYEE must WORK_FOR a DEPARTMENT
1
Cardinality: 1 (One)
Entity participates in at most one relationship instance
Use for: One-to-one or one-to-many relationships
Example:
EMPLOYEE―1―MANAGES―1―DEPARTMENT
N / M
Cardinality: N or M (Many)
Entity can participate in many relationship instances
Use for: One-to-many or many-to-many relationships
Example from slides:
EMPLOYEE―N―WORKS_ON―M―PROJECT
(min, max)
Min-Max Notation
Specifies minimum and maximum participation
(0,1) = optional one
(1,1) = mandatory one
(0,N) = optional many
(1,N) = mandatory many
(1,1) = mandatory one
(0,N) = optional many
(1,N) = mandatory many
Example from slides:
EMPLOYEE (1,1)―WORKS_FOR―(1,N) DEPARTMENT
Relationship Types by Cardinality
| Type | Notation | Description | Example from Slides |
|---|---|---|---|
| 1:1 | 1 ― 1 | One entity in A relates to at most one in B | EMPLOYEE MANAGES DEPARTMENT |
| 1:N | 1 ― N | One entity in A relates to many in B | DEPARTMENT has many EMPLOYEEs |
| N:1 | N ― 1 | Many entities in A relate to one in B | EMPLOYEE WORKS_FOR DEPARTMENT |
| M:N | M ― N | Many entities in A relate to many in B | EMPLOYEE WORKS_ON PROJECT |
Recursive (Unary) Relationships
Self-Referencing/Recursive Relationship
Same entity type participates in different roles
Use when: Entity relates to itself (e.g., supervision, prerequisite)
Example from slides:
EMPLOYEE supervises EMPLOYEE (supervisor role and supervisee role)
EER (Enhanced ER) Symbols
Specialization/Generalization Components
⊂
Subset Symbol (U-shaped arrow)
Indicates IS-A relationship from subclass to superclass
Points from subclass upward to circle connecting to superclass
Example:
SECRETARY ⊂ EMPLOYEE (SECRETARY IS-A EMPLOYEE)
○
Circle
Junction point connecting superclass to subclasses
Superclass connects to circle; circle connects to all subclasses
d
d (Disjoint Constraint)
Entity can be member of at most ONE subclass
Place 'd' inside or near the circle
Example from slides:
EMPLOYEE → {SECRETARY, TECHNICIAN, ENGINEER} with d constraint
o
o (Overlapping Constraint)
Entity can be member of MULTIPLE subclasses simultaneously
Place 'o' inside or near the circle
Example from slides:
PART → {MANUFACTURED_PART, PURCHASED_PART} with o constraint
――
Single Line (from superclass to circle)
Partial Specialization - not all entities need to be in a subclass
Some superclass entities may not belong to any subclass
══
Double Line (from superclass to circle)
Total Specialization - every entity must be in at least one subclass
Every superclass entity must belong to at least one subclass
Example from slides:
Every VEHICLE must be either CAR or TRUCK (total)
Specialization Constraint Combinations
| Disjointness | Completeness | Notation | Meaning |
|---|---|---|---|
| Disjoint | Total | d with double line | Every entity in exactly one subclass |
| Disjoint | Partial | d with single line | Entity in at most one subclass (or none) |
| Overlapping | Total | o with double line | Every entity in one or more subclasses |
| Overlapping | Partial | o with single line | Entity can be in multiple or no subclasses |
Category/Union Types
∪
Union Symbol (in circle)
Represents a Category (Union Type)
Subclass is subset of UNION of different superclasses with different keys
Example from slides:
OWNER ∪ {PERSON, BANK, COMPANY} - owner can be person OR bank OR company
――
Single Line to Union Circle
Partial Category - subset of union
Category holds subset of union of all superclass entities
══
Double Line to Union Circle
Total Category - holds union of all
Category holds complete union of all superclass entities
Key Difference:
- Specialization/Generalization: Entity is member of ONE superclass, may be in subclasses (inheritance)
- Category/Union: Entity is member of exactly ONE of multiple possible superclasses (union type)
Relational Model Notation
Schema Notation
R(A₁, A₂, ..., Aₙ)
Relation Schema
R = relation name, A₁...Aₙ = attributes
Example from slides:
EMPLOYEE(Fname, Lname, SSN, Bdate, Address, Salary, Dno)
Attribute
Underlined Attribute
Indicates Primary Key
Example:
EMPLOYEE(SSN, Name, Salary)
FK
Foreign Key
Attribute that references primary key of another relation
Often indicated with arrow or labeled as FK in diagrams
Example from slides:
EMPLOYEE(SSN, Dno) where Dno references DEPARTMENT(Dnumber)
→
Arrow (in diagrams)
Shows foreign key reference direction
Points from foreign key to referenced primary key
Tuple Notation
t[A]
Tuple Component
Value of attribute A in tuple t
Example:
t[SSN] refers to the SSN value in tuple t
t[A₁, A₂, ..., Aₙ]
Sub-tuple
Values of multiple attributes in tuple t
DDL (Data Definition Language) Notation
DDL Keywords
PRIMARY KEY
Defines primary key constraint
CREATE TABLE Student (
StudentID INT,
Name VARCHAR(50),
PRIMARY KEY (StudentID)
);
StudentID INT,
Name VARCHAR(50),
PRIMARY KEY (StudentID)
);
FOREIGN KEY
Defines foreign key constraint
FOREIGN KEY (Dno)
REFERENCES DEPARTMENT(Dnumber)
REFERENCES DEPARTMENT(Dnumber)
NOT NULL
Attribute cannot be null
Name VARCHAR(50) NOT NULL
ON DELETE CASCADE
Delete referenced rows when parent is deleted
FOREIGN KEY (Dno)
REFERENCES DEPARTMENT(Dnumber)
ON DELETE CASCADE
REFERENCES DEPARTMENT(Dnumber)
ON DELETE CASCADE
ON DELETE SET NULL
Set to NULL when parent is deleted
ON DELETE SET NULL
ON UPDATE CASCADE
Update foreign key when primary key changes
ON UPDATE CASCADE
Functional Dependency Notation
FD Symbols
X → Y
Functional Dependency
X functionally determines Y
If two tuples have same X value, they must have same Y value
Examples from slides:
SSN → ENAMEPNUMBER → {PNAME, PLOCATION}
{SSN, PNUMBER} → HOURS
X⁺
Closure of X
Set of all attributes determined by X
Used to find all attributes functionally dependent on X
F⁺
Closure of F
Set of all FDs implied by F
Types of Dependencies
Full Functional Dependency
Y depends on entire X (removing any attribute from X breaks dependency)
Example from slides:
{SSN, PNUMBER} → HOURS is full FD(neither SSN → HOURS nor PNUMBER → HOURS hold)
Partial Dependency
Y depends on part of composite key X
Example from slides:
{SSN, PNUMBER} → ENAME is partial(since SSN → ENAME also holds)
Violates 2NF
Transitive Dependency
X → Y and Y → Z (where Y is not a candidate key)
Example from slides:
SSN → DNUMBER and DNUMBER → DMGRSSNTherefore SSN → DMGRSSN is transitive
Violates 3NF
Armstrong's Axioms
| Rule | Notation | Meaning |
|---|---|---|
| Reflexivity | If Y ⊆ X, then X → Y | Trivial dependency |
| Augmentation | If X → Y, then XZ → YZ | Add same attributes to both sides |
| Transitivity | If X → Y and Y → Z, then X → Z | Chaining dependencies |
| Union | If X → Y and X → Z, then X → YZ | Derived from axioms |
| Decomposition | If X → YZ, then X → Y and X → Z | Derived from axioms |
Normal Forms
| Normal Form | Requirements | What it Prevents | Slide Reference |
|---|---|---|---|
| 1NF | All attributes are atomic (no multivalued or composite attributes) | Repeating groups, nested relations | Slide 09 - Slides 46-51 |
| 2NF | 1NF + No partial dependencies (non-prime attributes fully depend on entire key) | Partial dependencies on composite keys | Slide 09 - Slides 52-54 |
| 3NF | 2NF + No transitive dependencies (non-prime attributes don't depend on other non-prime attributes) | Transitive dependencies | Slide 09 - Slides 55-57 |
| BCNF | 3NF + Every determinant is a candidate key | Any dependency where determinant is not a superkey | Slide 09 - Slides 68-78 |
Remember: Every relation in BCNF is in 3NF, every 3NF is in 2NF, and every 2NF is in 1NF.
SQL Operators & Keywords
Comparison Operators
| Operator | Meaning | Example from Slides |
|---|---|---|
| = | Equal to | WHERE major = "CS" |
| <> | Not equal to | WHERE status <> 'active' |
| < | Less than | WHERE age < 25 |
| > | Greater than | WHERE salary > 30000 |
| <= | Less than or equal | WHERE quantity <= 10 |
| >= | Greater than or equal | WHERE rating >= 4 |
Logical Operators
AND
Both conditions must be TRUE
WHERE Fname='John' AND Lname='Smith'
OR
At least one condition must be TRUE
WHERE cus_areacode='615' OR cus_areacode='713'
NOT
Negates a condition
WHERE NOT status = 'inactive'
Pattern Matching
LIKE
Pattern matching with wildcards
WHERE Address LIKE '%Houston,TX%'
%
Matches any number of characters (0 or more)
Examples:
'A%' - starts with A'%son' - ends with son
'%data%' - contains data
_
Underscore (single character wildcard)
Matches exactly one character
Example:
'CS___' - CS followed by exactly 3 characters
Range & Set Operators
BETWEEN
Value within range (inclusive)
WHERE Salary BETWEEN 30000 AND 40000
IN
Value matches any in a list
WHERE Pno IN (1, 2, 3)
NOT IN
Value does not match any in list
NULL Handling
IS NULL
Tests if value is NULL
WHERE Super_ssn IS NULL
IS NOT NULL
Tests if value is not NULL
WHERE email IS NOT NULL
Important: Never use = NULL or <> NULL. Always use IS NULL or IS NOT NULL.
Subquery Operators
EXISTS
TRUE if subquery returns at least one row
WHERE EXISTS (SELECT *
FROM DEPENDENT
WHERE Ssn = Essn)
FROM DEPENDENT
WHERE Ssn = Essn)
NOT EXISTS
TRUE if subquery returns no rows
WHERE NOT EXISTS (SELECT *
FROM DEPENDENT
WHERE Ssn = Essn)
FROM DEPENDENT
WHERE Ssn = Essn)
= ANY / IN
Equals at least one value in set
= ANY is equivalent to IN
WHERE rating > ANY
(SELECT rating FROM Sailors
WHERE name='dustin')
(SELECT rating FROM Sailors
WHERE name='dustin')
> ALL
Greater than all values in set
WHERE Salary > ALL
(SELECT Salary FROM EMPLOYEE
WHERE Dno=5)
(SELECT Salary FROM EMPLOYEE
WHERE Dno=5)
UNIQUE
TRUE if no duplicate tuples in subquery result
Aggregate Functions
COUNT(*)
Counts number of rows
SELECT COUNT(*) FROM EMPLOYEE
COUNT(DISTINCT A)
Counts unique values in column A
SELECT COUNT(DISTINCT department)
FROM Student
FROM Student
SUM(A)
Sum of values in column A
SELECT SUM(Salary) FROM EMPLOYEE
AVG(A)
Average of values in column A
SELECT AVG(gpa) FROM Student
MAX(A)
Maximum value in column A
SELECT MAX(gpa) FROM Student
MIN(A)
Minimum value in column A
SELECT MIN(gpa) FROM Student
Grouping & Filtering
GROUP BY
Groups rows by column values
Used with aggregate functions
SELECT Dno, COUNT(*)
FROM EMPLOYEE
GROUP BY Dno
FROM EMPLOYEE
GROUP BY Dno
HAVING
Filters groups (used after GROUP BY)
WHERE filters rows, HAVING filters groups
GROUP BY Pnumber, Pname
HAVING COUNT(*) > 2
HAVING COUNT(*) > 2
ORDER BY
Sorts result by column(s)
ORDER BY D.Dname, E.Lname
ASC / DESC
Ascending or descending order
ORDER BY age ASC
ORDER BY rating DESC
ORDER BY rating DESC
Set Operations
UNION
Combines results, removes duplicates
SELECT name FROM students
UNION
SELECT name FROM professors
UNION
SELECT name FROM professors
UNION ALL
Combines results, keeps duplicates
INTERSECT
Returns only common rows
EXCEPT / MINUS
Returns rows from first query not in second
Join Types
INNER JOIN
Returns only matching rows from both tables
FROM A INNER JOIN B
ON A.id = B.id
ON A.id = B.id
LEFT OUTER JOIN
All rows from left table + matching from right
FROM Course
LEFT OUTER JOIN Faculty
ON Course.Lecturer_id = Faculty.id
LEFT OUTER JOIN Faculty
ON Course.Lecturer_id = Faculty.id
RIGHT OUTER JOIN
All rows from right table + matching from left
FULL OUTER JOIN
All rows from both tables
NATURAL JOIN
Joins on all common columns automatically
FROM EMPLOYEE
NATURAL JOIN DEPARTMENT
NATURAL JOIN DEPARTMENT
CROSS JOIN
Cartesian product (all combinations)
Other SQL Keywords
DISTINCT
Removes duplicate rows from result
SELECT DISTINCT sname
FROM sailors
FROM sailors
AS
Renames column or table (alias)
SELECT AVG(gpa) AS avg_gpa
*
Selects all columns
SELECT * FROM STUDENT
Quick Reference Guide
Cardinality Recognition
How to identify relationship types:
- 1:1 - Both sides marked with 1 or (0,1) or (1,1)
- 1:N - One side has 1 or (0,1)/(1,1), other has N or (0,N)/(1,N)
- M:N - Both sides have N/M or (0,N)/(1,N)
Common Pitfalls
Avoid these mistakes:
- Using = or <> with NULL (use IS NULL / IS NOT NULL)
- Forgetting DISTINCT when removing duplicates
- Using WHERE for aggregate conditions (use HAVING)
- Not specifying JOIN conditions (creates Cartesian product)
- Mixing aggregate and non-aggregate columns without GROUP BY
SQL Query Order of Execution
Conceptual execution order:
- FROM - Identify tables
- WHERE - Filter rows
- GROUP BY - Group rows
- HAVING - Filter groups
- SELECT - Choose columns
- ORDER BY - Sort result