Skip to content
AL-502 · Database Management Systems/Quick Revision Short Notes

Database Management Systems (AL-502) - Unit 2 Short Notes

How unit 2 is examined

Relational model concepts, keys and constraints, SQL (DDL, DML, complex queries, triggers), hashing, relational algebra and calculus; marks sit in Keys, SQL queries, joins and algebra operators.

Domains

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. <mark>A domain is the set of atomic values an attribute is allowed to take.</mark> Key points.

  1. Each attribute draws its values from one domain, such as integers 0-100 for Marks.
  2. Values are atomic, so a domain never holds a set or a list.
  3. Domain integrity is enforced with data types and CHECK.
  4. Two attributes may share a domain, but NULL may be allowed as a special value.

Tuples

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. <mark>A tuple is one row of a relation, an ordered list of values, one per attribute.</mark> Key points.

  1. A tuple represents one real-world entity or fact, such as one student.
  2. The number of attributes is the degree; the number of tuples is the cardinality.

Attributes

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. <mark>An attribute is a named column of a relation that holds one property of the entity, drawn from a domain.</mark> Key points.

  1. Attribute names are unique within a relation.
  2. Each attribute has a name and a domain, for example Marks with domain 0-100.
  3. The count of attributes is the degree of the relation.

Relations

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>A relation is a table of $n$-ary tuples: a subset of the Cartesian product $D_1 \times D_2 \times \dots \times D_n$ of the attribute domains.</mark> Key points.

  1. A relation has a name, a schema $R(A_1,\dots,A_n)$ and a set of tuples, its instance.
  2. Attributes are the columns, tuples the rows, domains the allowed values, and keys identify each tuple uniquely.
  3. Example: STUDENT(Roll, Name, Marks) with tuple (1, Asha, 72); degree 3.
  4. A relational database is a collection of such relations.

Asked: [7 marks] (Dec 2025) Explain relational data model concepts: relations, attributes, tuples, domains, and keys.

Characteristics of relations

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. <mark>A relation is a set of distinct tuples with unique, atomic-valued attributes, where order does not matter.</mark> Key points.

  1. Relation names are unique in the database and attribute names are unique in a relation.
  2. No duplicate tuples exist, because a relation is a set.
  3. Order of tuples and of attributes has no meaning.
  4. Every value is atomic (first normal form).

Keys

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Medium weight</span>

Definition. <mark>A key is an attribute or set of attributes that uniquely identifies a tuple in a relation.</mark> Key points.

  1. A super key is any set of attributes that is unique for every tuple, such as {Roll, Name}.
  2. A candidate key is a minimal super key; no proper subset of it is still unique.
  3. The primary key is the one candidate key chosen to identify tuples; it must be unique and NOT NULL, and a table has only one.
  4. Alternate keys are candidate keys not chosen as primary, such as Email.
  5. A composite key has more than one attribute, such as (Roll, Course) in ENROLL.
  6. A foreign key is an attribute in one relation that refers to the primary key of another (or the same) relation, giving the referential link.
  7. Integrity constraints are rules that keep data valid: domain (values from the domain), entity (primary key not NULL and unique) and referential (foreign key matches an existing primary key or is NULL).

Example.

Roll (PK) Name Email (alternate) DeptNo (FK to DEPT)
1 Asha [email protected] 10
2 Ravi [email protected] 20

Answer frame. Open with the definition of a key; give the STUDENT table above; develop points 1-7 in that order, with one example each; close with a line that primary key gives entity integrity and foreign key gives referential integrity.

Pitfall: Do not call every unique attribute a primary key; only one candidate key is chosen. Asked: [7 marks] (Nov 2019, Dec 2024) Explain primary key, foreign key and integrity constraints; explain in detail the various key constraints used in a database system.

Key attributes of relation

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. <mark>A prime (key) attribute is an attribute that belongs to some candidate key; the rest are non-prime attributes.</mark> Key points.

  1. In ENROLL(Roll, Course, Grade) with key (Roll, Course), Roll and Course are prime and Grade is non-prime.
  2. An attribute in any candidate key is prime, not only in the primary key.

Relational database

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>A relational database is a collection of related tables (relations) with their constraints, queried through relational languages.</mark> Key points.

  1. Design: find entities (Patient, Doctor, Visit, Bill, Insurance), give each a table with a primary key, and link them by foreign keys.
  2. Schema: PATIENT(PID, Name, DOB, InsID); DOCTOR(DID, Name, Spec); VISIT(VID, PID, DID, Date, Diagnosis); BILL(BID, VID, Amount, Paid); INSURANCE(InsID, Company, Address).
  3. VISIT gives doctors instant patient history by PID; BILL joined to PATIENT and INSURANCE lets the clerk bill every insurer, and all tables are in 3NF.

<figure class="ds-fig" style="margin:1.4rem 0;overflow-x:auto"><svg xmlns="http://www.w3.org/2000/svg" id="dsfig-u2-01" viewBox="0 0 431 252" width="431" height="252" role="img" aria-label="Doctor's office schema; Doc=DOCTOR, Vis=VISIT, Pat=PATIENT, Ins=INSURANCE; arrows are foreign keys"><style>#dsfig-u2-01 .e{stroke:#454C5A;stroke-width:1.4;fill:none}#dsfig-u2-01 .e.hi{stroke:#2340B8;stroke-width:2.6}#dsfig-u2-01 .n{fill:#FFFFFF;stroke:#16181D;stroke-width:1.4}#dsfig-u2-01 .n.hi{fill:#E3E9FC;stroke:#2340B8;stroke-width:2.2}#dsfig-u2-01 .n.rb-b{fill:#16181D;stroke:#16181D}#dsfig-u2-01 .n.rb-r{fill:#BD3227;stroke:#BD3227}#dsfig-u2-01 text{font-family:"JetBrains Mono",ui-monospace,Menlo,Consolas,monospace;font-size:13px}#dsfig-u2-01 .t{fill:#16181D;font-weight:500}#dsfig-u2-01 .t.inv{fill:#FFFFFF;font-weight:700}#dsfig-u2-01 .kd{stroke:#16181D;stroke-width:1.2}#dsfig-u2-01 .dot{fill:#16181D}#dsfig-u2-01 .ann{fill:#2340B8;font-size:11px;font-weight:700}#dsfig-u2-01 .lbl{fill:#6F7787;font-family:system-ui,-apple-system,sans-serif;font-size:12px;font-weight:700}#dsfig-u2-01 .ptr{fill:#2340B8;font-size:12px;font-weight:700}#dsfig-u2-01 .ah{fill:#454C5A}#dsfig-u2-01 .ah.hi{fill:#2340B8}#dsfig-u2-01 .wl rect{fill:#FFFFFF;stroke:#DCE0E7}#dsfig-u2-01 .wl .t{font-size:12px;font-weight:700}#dsfig-u2-01 .wl.hi rect{fill:#2340B8;stroke:#2340B8}#dsfig-u2-01 .wl.hi .t{fill:#FFFFFF}html.dark #dsfig-u2-01 .e{stroke:#B1B7C3}html.dark #dsfig-u2-01 .e.hi{stroke:#8FA3FF}html.dark #dsfig-u2-01 .n{fill:#161920;stroke:#E6E8ED}html.dark #dsfig-u2-01 .n.hi{fill:#1E2748;stroke:#8FA3FF}html.dark #dsfig-u2-01 .n.rb-b{fill:#E6E8ED;stroke:#E6E8ED}html.dark #dsfig-u2-01 .n.rb-r{fill:#FF7E71;stroke:#FF7E71}html.dark #dsfig-u2-01 .t{fill:#E6E8ED}html.dark #dsfig-u2-01 .t.inv{fill:#0F1115}html.dark #dsfig-u2-01 .kd{stroke:#E6E8ED}html.dark #dsfig-u2-01 .dot{fill:#E6E8ED}html.dark #dsfig-u2-01 .ann{fill:#8FA3FF}html.dark #dsfig-u2-01 .lbl{fill:#858D9C}html.dark #dsfig-u2-01 .ptr{fill:#8FA3FF}html.dark #dsfig-u2-01 .ah{fill:#B1B7C3}html.dark #dsfig-u2-01 .ah.hi{fill:#8FA3FF}html.dark #dsfig-u2-01 .wl rect{fill:#161920;stroke:#2A2E37}html.dark #dsfig-u2-01 .wl.hi rect{fill:#8FA3FF;stroke:#8FA3FF}html.dark #dsfig-u2-01 .wl.hi .t{fill:#0F1115}</style><defs><marker id="ah6" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="ah" d="M0,1 L9,5 L0,9 z"/></marker><marker id="ahh6" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path class="ah hi" d="M0,1 L9,5 L0,9 z"/></marker></defs><path class="e" d="M193,40 L61,40" marker-end="url(#ah6)"/><path class="e" d="M231,40 L363,40" marker-end="url(#ah6)"/><path class="e" d="M212,186 L212,61" marker-end="url(#ah6)"/><path class="e" d="M384,59 L384,191" marker-end="url(#ah6)"/><g class="wl"><rect x="109.2" y="31" width="33.6" height="18" rx="9"/><text class="t" x="126" y="40" dy=".35em" text-anchor="middle">DID</text></g><g class="wl"><rect x="281.2" y="31" width="33.6" height="18" rx="9"/><text class="t" x="298" y="40" dy=".35em" text-anchor="middle">PID</text></g><g class="wl"><rect x="195.2" y="117" width="33.6" height="18" rx="9"/><text class="t" x="212" y="126" dy=".35em" text-anchor="middle">VID</text></g><g class="wl"><rect x="360.5" y="117" width="47.1" height="18" rx="9"/><text class="t" x="384" y="126" dy=".35em" text-anchor="middle">InsID</text></g><circle class="n" cx="40" cy="40" r="18"/><text class="t" x="40" y="40" dy=".35em" text-anchor="middle">Doc</text><circle class="n" cx="212" cy="40" r="18"/><text class="t" x="212" y="40" dy=".35em" text-anchor="middle">Vis</text><circle class="n" cx="384" cy="40" r="18"/><text class="t" x="384" y="40" dy=".35em" text-anchor="middle">Pat</text><rect class="n" x="187" y="197" width="50" height="30" rx="15"/><text class="t" x="212" y="212" dy=".35em" text-anchor="middle">Bill</text><circle class="n" cx="384" cy="212" r="18"/><text class="t" x="384" y="212" dy=".35em" text-anchor="middle">Ins</text></svg><figcaption style="font-size:.82em;opacity:.72;margin-top:.45rem">Doctor's office schema; Doc=DOCTOR, Vis=VISIT, Pat=PATIENT, Ins=INSURANCE; arrows are foreign keys</figcaption></figure>

Asked: [7 marks] (Nov 2022) Design a possible schema for a doctor's office: doctors need immediate access to patient medical information and the records clerk must be sure all insurance companies are billed.

Schemas

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. <mark>A relational schema is the name of a relation with its attributes and domains, written $R(A_1,\dots,A_n)$.</mark> Key points.

  1. Example: STUDENT(Roll, Name, Marks).
  2. A database schema is the set of all relation schemas plus constraints.

Integrity constraints

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>Integrity constraints are rules the DBMS enforces so that every stored state is valid.</mark> Key points.

  1. Entity integrity: the primary key can never be NULL and must be unique.
  2. Referential integrity: a foreign key value must exist as a primary key in the referenced table, or be NULL.
  3. (i) Insert (NULL, 'T', 104) is rejected: it violates entity integrity, as E_ID is the primary key.
  4. (ii) Delete E3 is fine if no row references E3; if another table refers to E3 it is rejected, or it cascades or sets NULL by the declared rule.
  5. (iii) Update dno 104 to 109 changes E5's dno; if dno is a foreign key and 109 does not exist in the parent table it is rejected, otherwise it is allowed.

Asked: [7 marks] (Nov 2022) Discuss the issues with the insert (NULL key), delete of E3 and update of dno 104 to 109 on the Employee relation with E_ID as primary key.

Referential integrity

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>Referential integrity requires every non-NULL foreign key value to match an existing primary key value in the referenced relation.</mark> Key points.

  1. Delete options: RESTRICT (reject), CASCADE (delete referencing rows), SET NULL.
  2. Emp_Manager(Employee_ID, Manager_ID): Manager_ID is a foreign key to Employee_ID, ON DELETE CASCADE.
  3. Delete Employee_ID = 2. Rows with Manager_ID = 2 are (8,2) and (16,2). Rows with Manager_ID = 8 give (14,8). No row has Manager_ID = 14 or 16.
  4. Deleted tuples: (2,3), (8,2), (14,8), (16,2), four tuples.

Asked: [7 marks] (Nov 2022) Determine all tuples deleted by Delete From Emp_Manager Where Employee_ID = '2' (Manager_ID is a foreign key with on-delete cascade).

Intension and Extension

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. <mark>Intension is the schema of a relation, and extension is the set of tuples in it at a moment.</mark> Key points.

  1. Intension is fixed and holds names, domains and constraints.
  2. Extension (instance) changes with every insert, delete and update.
  3. Schema versus instance is the same idea.

Relational Query languages: SQL-DDL

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>DDL statements (CREATE, ALTER, DROP) define the structure of tables, while INSERT and SELECT handle their data.</mark> Key points.

  1. CREATE TABLE sets column names, data types and constraints.
  2. INSERT adds tuples and SELECT ... WHERE retrieves them.
  3. ALTER changes a table and DROP removes it.
CREATE TABLE STUDENT (Roll_No INT PRIMARY KEY, Name VARCHAR(30), Marks INT);
INSERT INTO STUDENT VALUES (1, 'Asha', 72);
INSERT INTO STUDENT VALUES (2, 'Ravi', 55);
SELECT * FROM STUDENT WHERE Marks > 60;  -- returns Asha

Asked: [7 marks] (Dec 2025) Write SQL queries to create a table STUDENT(Roll No, Name, Marks), insert two records, and retrieve students with Marks > 60.

DML

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>DML commands query and modify the data in tables: SELECT, INSERT, UPDATE, DELETE.</mark> Key points.

  1. SELECT: SELECT cols FROM table WHERE cond; reads rows, e.g. SELECT Name FROM STUDENT WHERE Marks > 60;.
  2. UPDATE: UPDATE table SET col = value WHERE cond; changes existing rows, e.g. UPDATE STUDENT SET Marks = 60 WHERE Roll_No = 2;.
  3. DELETE: DELETE FROM table WHERE cond; removes rows, e.g. DELETE FROM STUDENT WHERE Roll_No = 2;.
  4. Without WHERE, UPDATE and DELETE act on every row.

Asked: [7 marks] (Dec 2020) Explain the commands Select, Update and Delete with syntax.

Integrity constraints in SQL (table constraints)

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. <mark>SQL table constraints (NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, DEFAULT) are declared in CREATE TABLE to enforce validity.</mark> Key points.

  1. NOT NULL forbids empty values and UNIQUE forbids duplicates.
  2. CHECK tests a condition, e.g. CHECK (Marks BETWEEN 0 AND 100).
  3. FOREIGN KEY ... REFERENCES table(col) ON DELETE CASCADE enforces referential integrity.

Complex queries

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Medium weight</span>

Definition. <mark>A complex query combines joins, GROUP BY / HAVING, aggregates and nested subqueries in SELECT-FROM-WHERE form.</mark> Key points.

  1. Join conditions in WHERE link tables on common attributes.
  2. WHERE filters rows before grouping; HAVING filters groups after aggregation.
  3. A subquery in WHERE compares against a computed value.

Example. Nov 2019 (employee, works, company):

-- i
SELECT empname FROM works WHERE companyname = 'First Bank Corporation';
-- ii
SELECT e.empname, e.street, e.city FROM employee e, works w
WHERE e.empname = w.empname AND w.companyname = 'First Bank Corporation' AND w.salary > 200000;
-- iii
SELECT e.empname FROM employee e, works w, company c
WHERE e.empname = w.empname AND w.companyname = c.companyname AND e.city = c.city;

Nov 2023 (Employee table: E_ID, E_Name, Gender, Salary, Manager_ID, Dept_ID):

-- i  (answer: 101)
SELECT Dept_ID FROM Employee GROUP BY Dept_ID HAVING AVG(Salary) > 4000;
-- ii (answer: 101, 102)
SELECT Dept_ID FROM Employee WHERE Gender = 'M' GROUP BY Dept_ID HAVING AVG(Salary) > 2000;
-- iii (B, C, F, G, H)
SELECT E_Name FROM Employee WHERE Manager_ID = 1;
-- iv (F, G)
SELECT E_Name FROM Employee WHERE Dept_ID = 103 AND Manager_ID = 1;
-- v  (B, 5000, 101)
SELECT E_Name, Salary, Dept_ID FROM Employee
WHERE Salary = (SELECT MAX(Salary) FROM Employee WHERE Salary < (SELECT MAX(Salary) FROM Employee));
-- vi (1 A, 2 B, 5 E, 7 G, 8 H)
SELECT E_ID, E_Name FROM Employee WHERE Salary > (SELECT Salary FROM Employee WHERE E_Name = 'F');
-- vii (Dept 101, 101, 103)
SELECT Dept_ID FROM Employee WHERE Salary > (SELECT Salary FROM Employee WHERE E_Name = 'E');

Answer frame. Restate the schema; write each query on its own line with the clause order SELECT, FROM, WHERE, GROUP BY, HAVING; state the output beside it; close by noting which joins or subqueries were used.

Asked: [7 marks] (Nov 2019) Write SQL for employees of First Bank Corporation; those earning over 200000 with street and city; and those living in the same city as their company. Asked: [7 marks] (Nov 2023) Write SQL queries on the Employee relation: departments with average salary above 4000, male average above 2000, employees under Manager 1, Dept 103 with Manager 1, second highest salary, salary above F, salary above E.

Various joins

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. <mark>A join combines tuples of two relations on a condition: inner (matching only) or outer (also unmatched tuples, padded with NULL).</mark> Key points.

  1. Inner, equi and natural joins keep only matching tuples; natural join uses common attributes and keeps one copy.
  2. Left, right and full outer joins keep the unmatched tuples of the left, right or both sides.

Indexing

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>Internal hashing stores a record at address $h(K)$ in an in-memory table, where $h$ is a hash function such as $K \bmod M$.</mark> Key points.

  1. A good hash function spreads keys uniformly; a collision occurs when two keys give the same address.
  2. Open addressing puts the record in the next free slot (linear probing).
  3. Chaining keeps a linked list per address for overflow records.
  4. Double hashing uses a second hash function to compute the probe step.
  5. Performance is $O(1)$ on average and drops as the load factor rises.

Asked: [7 marks] (Jun 2020) Explain in detail about internal hashing techniques.

Triggers

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>A trigger is a stored rule that fires automatically on an event (INSERT, UPDATE, DELETE) when its condition holds, then runs an action (event-condition-action).</mark> Key points.

  1. It may fire once per statement or for each row.
  2. An assertion (see next topic) is checked on every change, but a trigger runs only on its named event.
CREATE TRIGGER low_marks BEFORE INSERT ON STUDENT FOR EACH ROW
BEGIN IF NEW.Marks < 0 THEN SET NEW.Marks = 0; END IF; END;

Asked: [7 marks] (Nov 2019) Explain triggers and assertions with an appropriate query.

Assertions

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. <mark>An assertion is a named condition over one or more tables that the database must always satisfy.</mark> Key points.

  1. It is like CHECK, but can span several tables.
  2. Any change that makes the condition false is rejected.
  3. Example: CREATE ASSERTION sal_chk CHECK (NOT EXISTS (SELECT * FROM emp WHERE salary < 0));

Relational algebra and relational calculus

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. <mark>Relational algebra is a procedural query language of operators on relations, while relational calculus is a non-procedural language that states what to retrieve.</mark> Key points.

  1. Both are formal languages with equal expressive power (relationally complete).
  2. Algebra says how to compute step by step; calculus only describes the result.

Relational algebra operations like select

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Medium weight</span>

Definition. <mark>SELECT $\sigma_{cond}(R)$ picks the tuples that satisfy a condition.</mark> Key points.

  1. SELECT $\sigma_{Marks>60}(STUDENT)$ keeps rows and all columns; it is commutative: $\sigma_{c1}(\sigma_{c2}(R)) = \sigma_{c2}(\sigma_{c1}(R))$.
  2. PROJECT $\pi_{A_1,\dots,A_k}(R)$ keeps the listed columns and removes duplicates: $\pi_{Name}(STUDENT)$.
  3. UNION $R \cup S$ has all tuples in R or S, without duplicates; R and S must be union compatible (same degree and domains), and it is commutative and associative.
  4. DIVISION $R \div S$ (universal quantification) gives values of A in R(A,B) paired with every B in S.

Example. STUDENT(Roll, Name, Marks): (1, Asha, 72), (2, Ravi, 55).

Expression Result
$\sigma_{Marks>60}$ (1, Asha, 72)
$\pi_{Name}$ Asha, Ravi
$\pi_{Name}$ of R $\cup$ {Ravi, Sita} Asha, Ravi, Sita

Division: TAKES(S, C) = (s1,c1), (s1,c2), (s2,c1) and COURSES = {c1, c2}; TAKES $\div$ COURSES = {s1}. Answer frame. Open with "relational algebra is a procedural query language"; give the symbol, definition and example table for each operator in the question; note the compatibility rule for UNION; close with the note that results are again relations.

Asked: [7 marks] (Nov 2019) Explain select, project and division operations with examples. Asked: [7 marks] (Dec 2024) Discuss in detail the operators SELECT, PROJECT and UNION with suitable examples.

Project

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. <mark>PROJECT $\pi_{A_1,\dots,A_k}(R)$ returns a relation containing only the listed columns of R.</mark> Key points.

  1. Duplicate tuples in the result are removed.
  2. It selects columns, while SELECT chooses rows.
  3. $\pi_{Name}(STUDENT)$ lists all names.

Join

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Medium weight</span>

Definition. <mark>Natural join $R \bowtie S$ combines tuples of R and S having equal values on all common attributes, keeping one copy of each.</mark> Key points.

  1. Theta join $R \bowtie_{\theta} S$ uses any condition; equi join uses only equality.
  2. Equivalent to $\sigma_{R.b = S.b}(R \times S)$ followed by dropping the duplicate column.
  3. Join is commutative and associative.
  4. Tuples with no match (like (8,9) in R) are lost in an inner join.

Example. Nov 2022: R = {(0,1), (4,5), (8,9)}, S = {(1,2), (5,2), (5,6), (5,10), (13,10)}, T = {(2,3), (6,7), (10,11), (10,3)}.

R $\bowtie$ S (a,b,c) then $\bowtie$ T on c (a,b,c,d)
(0,1,2) (0,1,2,3)
(4,5,2) (4,5,2,3)
(4,5,6) (4,5,6,7)
(4,5,10) (4,5,10,11), (4,5,10,3)

R $\bowtie$ S has 4 tuples; (R $\bowtie$ S) $\bowtie$ T has 5 tuples. Dec 2025: EMP has only Eid, so the employee is identified by Eid: $$\pi_{Eid}(EMP \bowtie \sigma_{Dname='Sales'}(DEPT))$$ Answer frame. For a numerical, name the common attribute, list matches attribute value by value, then join the result with T and give the final count; for the expression, write select, then join, then project in that order.

Asked: [7 marks] (Nov 2022) Find R natural-join S and (R natural-join S) natural-join T for the given R, S and T. Asked: [7 marks] (Dec 2025) For EMP(Eid, Dept) and DEPT(Dept, Dname), write relational algebra to find employees working in 'Sales'.

Division

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. <mark>Division $R \div S$ returns the values of the attributes of R not in S that are associated in R with every tuple of S.</mark> Key points.

  1. It answers "for all" queries, such as students who took all courses.
  2. R(A,B) $\div$ S(B) gives a relation on A.
  3. Formula: $R \div S = \pi_A(R) - \pi_A((\pi_A(R) \times S) - R)$.

Outer union

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Not asked since 2022</span>

Definition. <mark>Outer union combines two relations that are not union compatible, keeping all attributes of both and padding missing values with NULL.</mark> Key points.

  1. Result attributes are the union of both attribute sets.
  2. Common attributes are merged into one column.
  3. It is used for partially compatible relations, such as STUDENT and INSTRUCTOR.

Types of relational calculus: tuple and domain oriented

<span style="display:inline-block;padding:.16em .6em;border:1.5px solid currentColor;border-radius:999px;font-size:.68em;font-weight:700;letter-spacing:.06em;text-transform:uppercase;opacity:.75">Low weight</span>

Definition. <mark>Tuple relational calculus (TRC) uses tuple variables ranging over relations; domain relational calculus (DRC) uses variables ranging over attribute domains.</mark> Key points.

  1. TRC: $\{t \mid STUDENT(t) \wedge t.Marks > 60\}$. DRC: $\{\langle n \rangle \mid \exists r, m\,(\langle r, n, m \rangle \in STUDENT \wedge m > 60)\}$.
  2. Both use $\exists$ and $\forall$ quantifiers with logical connectives.
Point Tuple calculus Domain calculus
Variable ranges over whole tuples of a relation values from an attribute domain
Attribute access $t.Marks$ one variable per attribute
Membership $STUDENT(t)$ $\langle r, n, m \rangle \in STUDENT$
Result set of tuples set of value lists
Basis used by SQL used by QBE
Verbosity shorter longer, many variables

Asked: [7 marks] (Dec 2024) How does Tuple-oriented relational calculus differ from domain-oriented relational calculus?

Last-minute revision

  • Super key is unique; candidate key is a minimal super key; primary key is the chosen candidate, unique and NOT NULL.
  • Foreign key refers to a primary key; referential integrity means every non-NULL foreign key matches.
  • DML: SELECT, INSERT, UPDATE, DELETE; DDL: CREATE, ALTER, DROP.
  • Cascade delete of Employee_ID 2 removes (2,3), (8,2), (14,8), (16,2).
  • R $\bowtie$ S has 4 tuples; with T it has 5.
  • Sales employees: $\pi_{Eid}(EMP \bowtie \sigma_{Dname='Sales'}(DEPT))$.
  • Division answers "for all" queries.
  • Hash collisions: open addressing, chaining, double hashing.

Memory hooks

  • Keys ladder: Super, Candidate, Primary, Alternate; Foreign points outward.
  • SPJ: Select rows, Project columns, Join tables.
  • Sigma is Selection (S), Pi is Projection (P).
  • TRC is Tuple with t.attr; DRC is Domain with one variable per value.

Coverage checklist

  • Domains: covered.
  • Tuples: covered.
  • Attributes: covered.
  • Relations: Q13.
  • Characteristics of relations: covered.
  • Keys: Q7.
  • Key attributes of relation: covered.
  • Relational database: Q12.
  • Schemas: covered.
  • Integrity constraints: Q4.
  • Referential integrity: Q8.
  • Intension and Extension: covered.
  • Relational Query languages: SQL-DDL: Q9.
  • DML: Q3.
  • integrity con straints: covered.
  • Complex queries: Q1, Q2.
  • various joins: covered.
  • indexing: Q15.
  • triggers: Q16.
  • assertions: Q16.
  • Relational algebra and relational calculus: covered.
  • Relational algebra operations like select: Q10, Q11.
  • Project: covered.
  • Join: Q5, Q6.
  • Division: Q10.
  • outer union: covered.
  • Types of relational calculus i.e. Tuple oriented and domain oriented relational calculus and its operations: Q14.
Go to where you left off?

Quick Add to Notes

Save questions, your own notes and screenshots into notes filed by unit. It takes a free account.

Create free account

Have an account? Log in