PolyU | Database Principles
An undergraduate course exploring database principles through relational data operations, exact system state preservation, and SQL verification in the era of AI.
Course Overview
Content Summary
An undergraduate course exploring database principles through relational data operations, exact system state preservation, and SQL verification in the era of AI.
Think in data operations. Express them in SQL.
Author: Ran Cheng
Acknowledgments: Based on the DSAI2202 Database Principles lecture materials.
Learning Objectives
- Learners should understand what digital data is and how it represents real-world information.
- Learners should understand the necessity of persistent storage for long-term data preservation.
- Learners should understand key operational duties managed by modern database management systems.
- Learners should consolidate their understanding of how databases, persistent storage, and AI interact.
- Learners will understand how real-world domains are analyzed to capture data requirements.
- Learners will understand the steps required to build a complete conceptual ER model.
- Learners will understand the role of primary keys in enforcing uniqueness and row identification.
- Learners will review the core principles of moving from conceptual domain models to relational tables.
- Learners will understand the fundamental purpose of retrieving specific data from a database.
- Learners will apply comparison operators to specify exact or range-based conditions.
- Learners will restrict the number of rows returned by a query.
- Learners will review the foundational principles of retrieving and filtering database data.
Lessons
Lesson
Overview: Students install PostgreSQL 16 and pgAdmin 4 on their own computers (macOS and Windows), tour the pgAdmin browser tree, find the schema, create a database, run SQL in the Query Tool, and import a .sql file — while learning to ignore advanced server features (users, roles, privileges) that are outside the scope of this course.
Learning Outcomes:
- Learners will install PostgreSQL and pgAdmin on their own computer (macOS or Windows).
- Learners will understand the server/client model (PostgreSQL server on port 5432, pgAdmin as the client).
- Learners will navigate pgAdmin to locate databases, schemas, and tables.
- Learners will create a database and execute SQL queries in the pgAdmin Query Tool.
- Learners will import a .sql file into their local PostgreSQL server.
Overview: Covers entity-relationship modeling, primary/foreign keys, and relational table translations.
Learning Outcomes:
- Learners will understand how real-world domains are analyzed to capture data requirements.
- Learners will understand the steps required to build a complete conceptual ER model.
- Learners will understand the role of primary keys in enforcing uniqueness and row identification.
- Learners will review the core principles of moving from conceptual domain models to relational tables.
Overview: Examines selection versus projection, filtering conditions, and basic SQL query reading.
Learning Outcomes:
- Learners will understand the fundamental purpose of retrieving specific data from a database.
- Learners will apply comparison operators to specify exact or range-based conditions.
- Learners will restrict the number of rows returned by a query.
- Learners will review the foundational principles of retrieving and filtering database data.
Overview: Focuses on database state changes, insert/update/delete operations, and null handling.
Learning Outcomes:
- Learners will understand how databases transition between states through modifications.
- Learners will understand how to target specific rows for modification using condition clauses.
- Learners will understand the operational differences between NULL and other default states.
- Learners will review key concepts regarding database state changes and null handling.
Overview: Discusses aggregation granularity, row-level vs group-level conditions, and aggregate functions.
Learning Outcomes:
- Learners will understand the fundamental purpose of summarising large datasets into meaningful metrics.
- Learners will understand how the WHERE clause filters individual rows prior to any grouping or summarisation.
- Learners will understand how to order summary results using the ORDER BY clause with aggregate expressions.
- Learners will synthesize core concepts of aggregation, grouping conditions, and query execution structure.
Overview: Explains multi-table separation, primary/foreign key tracing, and inner join semantics.
Learning Outcomes:
- Learners will understand why relational databases separate data across multiple tables and how relationships are established.
- Learners will master how to manually and conceptually trace data pathways across tables using keys.
- Learners will understand how database engines evaluate equality conditions during joins.
- Learners will review key takeaways regarding table separation, keys, and inner join semantics.
Overview: Covers outer joins, missing relationships, null handling in joins, and many-to-many duplication.
Learning Outcomes:
- Learners will understand the role of reasoning across relationships in relational databases.
- Learners will learn how to detect unlinked or orphaned records using outer joins.
- Learners will diagnose the structural causes of unexpected data inflation in queries.
- Learners will consolidate their understanding of outer joins, null handling, and duplication control.
Overview: Explores complex query decomposition, intermediate results, subqueries, and CTEs.
Learning Outcomes:
- Learners will understand the fundamental purpose of combining multiple database operations into unified queries.
- Learners will analyze how database engines execute subqueries and recognize performance implications.
- Learners will understand how to traverse hierarchical relationships using recursive Common Table Expressions.
- Learners will review key concepts of query composition, subqueries, and CTEs to solidify their understanding.
Overview: Introduces normalization, data anomalies, functional dependencies, and 1NF/2NF/3NF.
Learning Outcomes:
- Learners will understand why proper data structuring is essential for reliable database management.
- Learners will analyze sample datasets to identify and map functional dependencies.
- Learners will define Second Normal Form and its reliance on full functional dependency.
- Learners will synthesize core principles of data anomalies, functional dependencies, and normalization.
Overview: Addresses transaction management, commit/rollback, and concurrency control.
Learning Outcomes:
- Learners should understand why syntactically correct SQL queries can produce unexpected results or failures across different database systems.
- Learners should understand how the commit command finalizes transaction changes and makes them permanent.
- Learners should understand consistency issues caused by data changing between reads within a transaction.
- Learners should synthesize transaction management and concurrency principles to build reliable database applications.
Overview: Focuses on execution plans, query costs, indexes, and performance optimization.
Learning Outcomes:
- Learners should understand why a query can produce the correct logical result while performing poorly.
- Learners should understand how indexes alter data access paths to accelerate retrieval.
- Learners should understand how different physical join algorithms affect query execution time.
- Learners should understand core principles for maintaining efficient database query performance.
Overview: Examines AI-generated SQL verification, syntactic vs semantic correctness, and permissions.
Learning Outcomes:
- Learners should understand the growing role and inherent risks of using artificial intelligence to interact with databases.
- Learners should understand how privilege levels dictate what an automated AI system is allowed to do within a database.
- Learners should understand how technical guardrails and isolated environments protect databases from rogue AI queries.
- Learners should synthesize core principles regarding safe, verifiable, and responsible AI usage in database management.
Overview: Compares relational databases with document, key-value, distributed, and vector storage systems.
Learning Outcomes:
- Learners will understand the inherent constraints and boundaries of relational databases in modern software applications.
- Learners will analyze why scaling relational databases horizontally across multiple servers is complex.
- Learners will understand the purpose and mechanisms of vector databases for machine learning applications.
- Learners will synthesize key takeaways on database selection and polyglot persistence.
Lab
This lab introduces the fundamentals of PostgreSQL, guiding students through the installation of the database server and the pgAdmin 4 management tool. Students will learn how to connect to their local database, execute basic SQL queries, and understand the core architecture of a relational database management system.
This lab explores the limitations of flat spreadsheets, such as data redundancy and update anomalies, and introduces relational database design as a solution. Students learn to identify entities and relationships to structure data into consistent, normalized tables that ensure integrity and prevent errors.
This lab focuses on using PostgreSQL to identify at-risk students by filtering data based on eligibility and academic performance criteria. Students will learn to classify database fields, verify data integrity, and apply SELECT and FROM clauses to extract prioritized information for support interventions.
This lab focuses on safely maintaining a student database in PostgreSQL by practicing precise INSERT, UPDATE, and DELETE operations. Students learn to verify table constraints, establish a consistent starting state, and predict row-count impacts to ensure data integrity during maintenance tasks.
This lab introduces techniques for grouping and summarizing course enrolment data in PostgreSQL using aggregate functions like COUNT, SUM, AVG, MIN, and MAX. Students will learn how to handle NULL values, filter data with WHERE clauses, and use DISTINCT to generate accurate performance reports for a university registrar.
This lab introduces the use of SQL `INNER JOIN` clauses to connect related data across multiple tables in a PostgreSQL database. Students will learn how to use primary and foreign keys to link student profiles, course details, and enrolment records to generate comprehensive reports.
This lab explores how to use different SQL join types—INNER, LEFT, RIGHT, FULL, and CROSS—to control which rows are retained when reconciling data between two sources. Students will learn to manage unmatched records and generate specific reports by applying the appropriate join logic to handle missing or non-matching IDs.
This lab focuses on composing complex PostgreSQL queries to analyze student performance by comparing recent assessment scores against an earlier baseline. Students will learn to use scalar subqueries and correlated subqueries to calculate averages dynamically and filter data based on specific performance decline thresholds.
This lab focuses on identifying and resolving data anomalies within a non-normalized registration sheet by decomposing it into five distinct, structured tables. Students will learn to detect issues like duplicate records, inconsistent spellings, and missing values to effectively transition from a flat, redundant dataset to a relational model.
This lab explores the critical role of transaction boundaries in maintaining data integrity when multiple concurrent processes interact with shared database records. Students will learn to use explicit transactions and rollback mechanisms to ensure that multi-step operations are processed as atomic units, preventing partial updates and data corruption.
This lab teaches students how to analyze and optimize SQL query performance by interpreting PostgreSQL execution plans using `EXPLAIN (ANALYZE, BUFFERS)`. By learning to identify inefficient operations like sequential scans and understanding how to read execution plan trees, students will practice making targeted improvements to reduce database resource consumption.
This lab teaches students how to critically evaluate AI-generated SQL by applying a four-question review loop focused on runnability, accuracy, scope, and permissions. By performing a three-pass analysis—checking intent, schema validity, and semantic correctness—students learn to identify hallucinations, destructive operations, and logical errors before executing code.
This lab serves as a comprehensive semester review, guiding students through a series of self-assessment stations that cover database design, SQL operations, and system reliability. By revisiting key concepts from Labs 1–13, students will practice identifying the core questions behind each topic to reinforce their understanding of how these skills integrate for exams.
Mock
This mock exam provides a comprehensive review of core database principles, including SQL querying, transaction management, schema design, and performance optimization. It serves as a practice tool to reinforce key concepts such as data integrity, join operations, and the application of the principle of least privilege.
Topic
This lesson introduces database transactions as indivisible units of work that ensure data integrity through atomicity, durability, and controlled visibility. Students will learn how to use commit and rollback operations to manage these boundaries and understand how isolation levels influence the visibility of concurrent database changes.