DBMS & SQLLevel 4
PART 1 • RELATIONAL FOUNDATIONS

Represent Data as Relations and Protect Its Meaning

Move from an ER design to precise relations, choose keys deliberately and use integrity constraints to prevent invalid states.

Level 04 of 18Foundation90–120 minutesLevel 3 recommended
BY THE END, YOU CAN
  • Use relational terminology precisely.
  • Calculate degree and cardinality.
  • Distinguish every important key type.
  • Diagnose integrity violations.
  • Map common ER patterns to tables.
  • Explain NULL without treating it as zero.
01 • SPEAK THE RELATIONAL LANGUAGE

A Relation Has Structure, Values and Meaning

The familiar word “table” is useful, but formal terms help us reason correctly.

Relation schemaSTUDENT(student_id, name, branch, cgpa)
student_idnamebranchcgpa
101AnuAIML8.6
102BharatCSE7.9
103CharanAIML9.1
Attribute one named columnTuple one rowDomain allowed values for an attributeRelation instance the current set of tuples
Relation

A named set of tuples sharing the same attributes.

Tuple

An ordered collection of attribute values representing one fact.

Attribute

A named role or property within the relation schema.

Domain

The permitted atomic values and meaning for an attribute.

Degree / arity

Number of attributes. STUDENT above has degree 4.

Cardinality

Number of tuples. The displayed instance has cardinality 3.

02 • RECOGNIZE A RELATION

Important Mathematical Properties

01

Unique relation name

A schema gives each relation a distinct name within its namespace.

02

Unique attribute names

Each attribute is distinguishable inside one relation.

03

Atomic domain values

Each cell holds one value from its attribute's domain in the basic relational model.

04

No duplicate tuples

A mathematical relation is a set, and sets do not contain duplicates.

05

Row order is irrelevant

A query must request ordering explicitly when presentation order matters.

06

Column order is not meaning

Attributes are referenced by role or name, not visual position.

03 • IDENTIFY WITHOUT AMBIGUITY

Keys Form a Family, Not a List to Memorize

SUPER KEY

Any unique attribute set

{student_id} and {student_id, name} may both uniquely identify a student. The second contains an unnecessary attribute.

CANDIDATE KEY

A minimal super key

It is unique, and removing any attribute destroys that guarantee.

PRIMARY KEY

The chosen candidate key

The designer selects one candidate as the main identifier. It must be unique and not NULL.

ALTERNATE KEY

An unchosen candidate key

Still unique, but not selected as the primary key.

COMPOSITE KEY

A key containing multiple attributes

(student_id, course_id) can identify one enrolment.

FOREIGN KEY

A reference to another relation

ENROLMENT.student_id references STUDENT.student_id.

SURROGATE KEY

A system-created identifier

An artificial ID has no business meaning but can provide a stable compact reference.

NATURAL KEY

An identifier from the domain

Examples may include a carefully governed registration number or ISBN.

All attribute setsSuper keysCandidate keys→ choose one →Primary key
04 • CLASSIFY

Interactive Key Explorer

For this exercise, roll number, institutional email and Aadhaar each uniquely identify a student. Test different attribute sets.

STUDENT
SELECT ATTRIBUTES

What kind of attribute set is it?

A key must first guarantee uniqueness; a candidate key must also be minimal.

05 • PREVENT INVALID STATES

Integrity Constraints Keep Data Meaningful

DOMAIN INTEGRITY

Every value belongs to its allowed domain

CGPA may be constrained to 0–10; branch may be limited to approved codes.

CHECK (cgpa BETWEEN 0 AND 10)
KEY CONSTRAINT

Candidate-key values remain unique

Two students cannot share the same institutional email when it is a candidate key.

UNIQUE (email)
ENTITY INTEGRITY

Primary-key components cannot be NULL

Every stored entity must have a known, unique identity.

PRIMARY KEY (student_id)
REFERENTIAL INTEGRITY

A foreign key references an existing target or is NULL when allowed

An enrolment cannot name a student that does not exist.

FOREIGN KEY (student_id) REFERENCES student

What happens when a referenced row changes?

RESTRICT / NO ACTION reject the parent changeCASCADE propagate it to matching childrenSET NULL remove the reference when NULL is permittedSET DEFAULT replace it with a valid default reference
06 • EXECUTE & DEBUG

Try to Insert a Student Row

The simulated schema checks primary key, domain, candidate key and foreign-key rules.

READY

The candidate row has not been checked.

Known student IDs: 101, 102 and 103. Known email: [email protected]. Valid branches: AIML, CSE and ECE.

07 • MAP THE CONCEPTUAL DESIGN

Interactive ER-to-Relational Mapper

Select an ER pattern to see the resulting relations, keys and placement decision.

08 • REASON ABOUT MISSING VALUES

NULL Means Unknown, Missing or Not Applicable

UNKNOWN

The student's emergency phone exists but is not currently known.

MISSING

The value was expected but has not yet been entered.

NOT APPLICABLE

A spouse_name value does not apply to an unmarried person.

NULL is not:

0'' (empty string)'NULL' (text)FALSE

Comparisons involving NULL usually produce UNKNOWN. SQL uses IS NULL and IS NOT NULL, not = NULL.

09 • CHECK YOUR UNDERSTANDING

Six Formative Concept Checks

1. What is the degree of R(A, B, C, D)?

2. Which is a minimal super key?

3. Which rule prevents a NULL primary key?

4. How is an M:N relationship normally mapped?

5. Which statement about NULL is correct?

6. A foreign key value normally must:

Answered correctly: 0 of 6
10 • EXPLAIN & PREPARE

University and Interview Questions

2-MARK QUESTIONS
  1. Define degree and cardinality.
  2. What is a domain?
  3. Define candidate key.
  4. State entity integrity.
  5. What does NULL represent?
5-MARK QUESTIONS
  1. Explain all important key types with examples.
  2. Explain relational integrity constraints.
  3. Map 1:1, 1:N and M:N relationships.
  4. Describe the properties of a relation.
INTERVIEW / DESIGN
  1. Natural key or surrogate key—how do you decide?
  2. Can a foreign key contain duplicates?
  3. Can it contain NULL?
  4. Why is email risky as a primary key?
  5. What happens during ON DELETE CASCADE?
Show the key-identification reasoning framework
  1. List attribute sets that uniquely identify every legal tuple.
  2. Remove redundant attributes to obtain minimal super keys.
  3. Call every remaining minimal set a candidate key.
  4. Select a stable, compact and controlled candidate as primary key.
  5. Enforce other candidate keys with uniqueness constraints.
  6. Use foreign keys wherever another relation must be referenced.

You Can Now Build and Protect Relations

  • A relation schema defines structure; its instance contains current tuples.
  • Degree counts attributes and relational cardinality counts tuples.
  • Candidate keys are minimal super keys; one becomes primary.
  • Domain, key, entity and referential integrity prevent invalid states.
  • ER patterns map systematically to relations and foreign keys.
  • NULL is a marker for missing meaning, not an ordinary value.
COURSE CHECKPOINT

Mark this level when you can identify keys, validate rows and map the common ER patterns without notes.

Saved in this browser only.