16.1 KB · commit 40bb182
← Previous: T03.3: Referential Integrity and Foreign Key Syntax | 🏠 Index | Next: T04.1: Basic Relational Algebra Operators →
Topic: T03 — Relational Model, Keys & Integrity | Priority: 🟢 | Exam Frequency: 0/7 finals (+ CT-01 Q02) (05 marks) Sources: Silberschatz 7e Ch. 2 (§2.4, pp. 46–47) · Lecture Deck 02 (Slide 8) · CT-01 Q.02
A relational schema diagram gives you a clean visual blueprint of an entire database at a glance. It shows every table as a box, lists its columns, underlines primary keys, and connects foreign keys to their parent tables using directed arrows. In RUET exams, drawing a schema diagram is a popular way to test whether you understand how tables link together through keys, and it appeared directly in CT-01 for 5 marks.
Schema Diagram: A schema diagram is a visual blueprint of a relational database schema. It displays each relation as a rectangular box with the relation name in the header and all its attributes listed inside.
Foreign-Key Arrow Convention: In a schema diagram, primary key attributes are underlined inside their relation box. Each foreign-key constraint is drawn as a directed arrow starting from the foreign key in the child relation and pointing to the primary key of the parent relation.
When a database has five or ten tables, reading raw SQL CREATE TABLE statements makes it hard to see how tables connect. A schema diagram turns those text definitions into a wiring map. Underlining the primary key shows what uniquely identifies each row, and drawing an arrow from a foreign key to a primary key shows exactly which parent table validates that column's values.
In the Silberschatz textbook and lecture slides, every relational schema diagram is built from four simple parts:
+-----------------------+ +-----------------------+
| Courses | | Instructors |
+-----------------------+ +-----------------------+
| course_id (PK) | | instructor_id (PK) |
| title | | name |
| instructor_id (FK) ---+-------------->| dept_name |
| credits | | salary |
+-----------------------+ +-----------------------+
The arrow direction in a relational schema diagram follows one strict rule:
Students frequently lose marks by drawing the arrow backward from parent to child. A simple way to remember the right direction is that the child foreign key "looks up to" the parent primary key for permission, so the arrow always points to the parent primary key.
It is very common to mix up relational schema diagrams with ER diagrams during a timed test. They represent different stages of database design and use completely different shapes:
| Feature | Relational Schema Diagram | Entity-Relationship (ER) Diagram |
|---|---|---|
| Model Level | Logical / Table-Level Relational Model | Conceptual Design Model |
| Basic Shapes | Rectangular boxes divided into header and column list | Rectangles (Entities), Diamonds (Relationships), Ovals (Attributes) |
| Connections | Directed arrows from child FK to parent PK | Lines connecting entities to relationship diamonds |
| Attribute Display | Listed as text rows inside the table box | Drawn as separate ovals attached to boxes or diamonds |
| Keys | Primary keys are underlined inside the box and foreign keys start arrows | Primary keys are underlined inside attribute ovals |
| Exam Trap | Drawing diamonds or ovals here costs you all marks | Drawing table column boxes here costs you all marks |
Both Silberschatz and Lecture Deck 02 (Slide 8) use the 11-table University database as their main reference schema. Notice how composite primary keys (such as in section and takes) have multiple underlined columns, and foreign keys are shown with → pointing to the referenced table:
classroom (building,room_number,capacity)department (dept_name,building,budget)course (course_id,title,dept_name,credits)
instructor (ID,name,dept_name,salary)
section (course_id,sec_id,semester,year,building,room_number,time_slot_id)
teaches (ID,course_id,sec_id,semester,year)
student (ID,name,dept_name,tot_cred)
takes (ID,course_id,sec_id,semester,year,grade)
advisor (s_id,i_id)
time\_slot (time_slot_id,day,start_time,end_time)prereq (course_id,prereq_id)
Branch, Account, Depositor)Before tackling the 5-table ECE department problem in the Golden Questions section, let us walk through a quick 3-table banking schema to see how you turn relational schemas into a box-and-arrow diagram.
Suppose we want to model bank branches, customer accounts, and which customer owns which account:
Account, branch_name is a foreign key pointing to Branch(branch_name).Depositor, account_number is part of a composite primary key, and it also acts as a foreign key pointing to Account(account_number).+--------------------+ +--------------------+ +--------------------+
| Depositor | | Account | | Branch |
+--------------------+ +--------------------+ +--------------------+
| customer_id (PK) | | account_number(PK)<+--+ | branch_name (PK) <+--+
| account_number(PK)-+--+ | branch_name (FK) --+--+-->| branch_city | |
+--------------------+ | | balance | | | assets | |
+-->+--------------------+ +---+--------------------+--+
Notice how each arrow starts at the foreign key column in the referencing table (Depositor or Account) and lands squarely on the underlined primary key in the parent table (Account or Branch).
| Year & Question | Marks | Scenario / Data Given | Key Result / Answer Summary |
|---|---|---|---|
| CT-01 Q.02 | 5 | ECE department (Students, Courses, Instructors, Classroom, Results) | Underline PKs in 5 table boxes, draw 4 directed foreign key arrows to parent PKs. |
Appeared: CT-01 Q.02 — (05 marks)
Question:
Draw a schema diagram for ECE, including 5 tables (Students, Courses, Instructors, Classroom, Results).
Full Answer:
Before drawing, specify each schema in relational notation:
Figure 2: Complete relational schema diagram for ECE showing primary keys and foreign key constraints.
Question:
Draw a relational schema diagram for a university database consisting of Department, Instructor, Course, and Section. Clearly indicate primary keys and foreign key constraints.
Answer:
dept_name in Department, ID in Instructor, course_id in Course, and composite key (course_id, sec_id, semester, year) in Section.Instructor.dept_name → Department.dept_nameCourse.dept_name → Department.dept_nameSection.course_id → Course.course_idSource: Silberschatz 7e · Chapter 2 (Exercise 2.13)
Exam Relevance: High-Probability Exam Diagram Question (CT-01 & Finals)
Key Tested Concept: Visual schema diagrams: relation boxes, underlined primary keys, and foreign-key reference arrows.
Problem Statement:
Construct a formal Relational Schema Diagram for the classic bank database containing the following relations:
- branch(branch_name,branch_city,assets)
- customer(customer_id,customer_name,customer_street,customer_city)
- account(account_number,branch_name,balance)
- loan(loan_number,branch_name,amount)
- depositor(customer_id,account_number)
- borrower(customer_id,loan_number)
Model Exam-Style Solution:
Schema Diagram Conventions:
Schema Diagram:
Figure 4: Schema Diagram for the Bank Database (Silberschatz 7e Fig. 2.18).
account.branch_name → branch.branch_nameloan.branch_name → branch.branch_namedepositor.customer_id → customer.customer_iddepositor.account_number → account.account_numberborrower.customer_id → customer.customer_idborrower.loan_number → loan.loan_number ■💡 RUET Exam Takeaway: In schema diagrams, arrowheads must point to the referenced primary key, NOT the other way around. Examiners deduct marks if the arrow points from parent to child.
← Previous: T03.3: Referential Integrity and Foreign Key Syntax | 🏠 Index | Next: T04.1: Basic Relational Algebra Operators →