DBMS & SQL Fundamentals:
Comprehensive Study Notes
What is a Database and DBMS
A Database is an organized collection of structured information, typically stored
electronically in a computer system.
A Database is usually controlled by a Database Management System (DBMS).
Together, the data and the DBMS, along with the applications that are associated with them,
are referred to as a database system.
A Database System is often shortened to just database.
A DBMS is software that provides an interface to manage and interact with databases. It
enables users to create, read, update, and delete (CRUD) data in a database.
A DBMS can manage various types of databases: hierarchical, network, relational, object-
oriented, and others.
Functionality of a DBMS includes:
Data storage, retrieval, and update operations
Administrative tasks like backup, recovery, and security
Abstraction of physical storage details, allowing interaction at a higher level
Confusing Acronyms (as introduced):
Database Management System (DMS)
Relational Database Management System (RDMS)
Structured Query Language (SQL)
Objectives of a DBMS/date-handling system include providing an abstraction layer, ensuring
data integrity, and enabling multi-user access.
Relational Database Management System (RDBMS)
An RDBMS is a type of DBMS designed to manage relational databases.
In a relational database, data is organized into tables (relations).
Tables consist of rows (records) and columns (fields).
Relationships between tables are established through foreign keys.
RDBMS features beyond a standard DBMS include:
Referential integrity
Normalization
ACID properties: Atomicity, Consistency, Isolation, Durability
SQL as the primary language for querying and data management
Examples of RDBMS: Oracle, MySQL, PostgreSQL, Microsoft SQL Server.
Structured Query Language (SQL)
SQL is a standardized programming language used to manage and manipulate relational
databases.
SQL interacts with an RDBMS to perform tasks such as querying data, updating records,
creating tables, and setting permissions.
SQL functionalities are categorized as:
DDL (Data Definition Language): define schema, e.g., CREATE, ALTER, DROP
DML (Data Manipulation Language): manipulate data, e.g., SELECT, INSERT,
UPDATE, DELETE
DCL (Data Control Language): control access, e.g., GRANT, REVOKE
TCL (Transaction Control Language): manage transactions, e.g., COMMIT, ROLLBACK
SQL is declarative: you specify what you want to achieve, and the engine determines how to
execute it.
Examples of SQL commands:
SELECT: Retrieve data from a database
INSERT: Add new records to a table
UPDATE: Modify existing data
DELETE: Remove records
Summary of Differences (DBMS vs RDBMS vs SQL)
DBMS is a broad term for software that manages databases, irrespective of data model.
RDBMS is a specific type of DBMS that uses relational databases, tables, and SQL.
SQL is the language used to interact with relational databases managed by an RDBMS.
Data Models Overview
Relational Database Model (RDM):
Data organized in tables (relations) with rows (tuples) and columns (attributes).
Relationships via keys; supports normalization and ACID properties.
SQL-based querying and management.
Examples: MySQL, PostgreSQL, Oracle, Microsoft SQL Server.
Document Database Model: documents stored in formats like JSON, BSON, or XML;
collections of documents.
Schema-less or flexible schema.
Query languages or APIs vary per database.
Use cases: unstructured or semi-structured data.
Examples: MongoDB, CouchDB, Firebase Firestore.
Key-Value Database Model: data stored as key-value pairs; each key maps to a single value.
Schema-less; values can be any type.
High performance for reads/writes; good for caching and real-time apps.
Examples: Redis, Amazon DynamoDB, Riak.
Graph Database Model: data modeled as nodes, edges, and properties.
Flexible schema for complex relationships.
Query languages: Cypher (e.g., Neo4j), Gremlin (Apache TinkerPop).
Use cases: social networks, recommendation engines.
Examples: Neo4j, Amazon Neptune, ArangoDB.
Wide Columnar Database Model: tables with rows and columns grouped into column
families; dynamic column addition.
Optimized for distributed, large-scale data with high read/write throughput.
Use cases: big data and real-time analytics.
Examples: Apache Cassandra, HBase, ScyllaDB.
Relational Data Model Details (RDBMS)
Relational model characteristics:
Tables (relations) with rows (records) and columns (fields)
Relationships via primary keys and foreign keys
Schema-defined tables with predefined relationships
Uses SQL for management and querying
=
ACID properties: ACID
(extAtomicity, extConsistency, extIsolation, extDurability)
Examples of RDBMSs: Oracle, MySQL, PostgreSQL, Microsoft SQL Server
Key SQL Concepts and Commands
SQL components: DDL, DML, DCL, TCL
DDL: CREATE, ALTER, DROP (define schema)
DML: SELECT, INSERT, UPDATE, DELETE (manipulate data)
TCL: COMMIT, ROLLBACK (transaction control)
Example commands:
CREATE TABLE Employees (EmployeeID INT PRIMARY KEY, FirstName
VARCHAR(50), LastName VARCHAR(50), DepartmentID INT);
CREATE TABLE Departments (DepartmentID INT PRIMARY KEY, DepartmentName
VARCHAR(50));
INSERT INTO Employees (EmployeeID, FirstName, LastName, DepartmentID)
VALUES (1, 'John', 'Doe', 101), (2, 'Jane', 'Smith', 102);
SELECT Employees.FirstName, Employees.LastName,
Departments.DepartmentName
FROM Employees JOIN Departments ON Employees.DepartmentID =
Departments.DepartmentID;
Declarative vs Imperative SQL
Declarative SQL: describes the desired outcome; the SQL engine decides the execution plan.
Example:
SELECT extname, extageFROM extU sersW HEREextage > 18
Imperative SQL (Procedural Extensions): explicit control flow, loops, and variables within
procedural code (e.g., T-SQL, PL/SQL, PL/pgSQL).
Example (T-SQL):
sql DECLARE @Sum INT = 0; DECLARE @i INT = 1; WHILE @i <= 10 BEGIN
SET @Sum = @Sum + @i; SET @i = @i + 1; END; SELECT @Sum AS Total;
Key difference: Declarative focuses on the result; Imperative focuses on how to achieve it.
Cursor and Fetch Status (SQL Server specific)
When using cursors, @@FETCH_STATUS indicates the result of the last FETCH:
0: Fetch successful
-1: Fetch failed because there are no more rows in the result set
-2: Fetch failed because the requested row does not exist (e.g., moving before first
or after last)
Data Examples and Practice Scenarios
Amazon data example (from slides):
Tables: Customers, Orders, Products
Sample rows shown (simplified):
Customers: CustomerID, Name, Address
Orders: OrderID, CustomerID, OrderDate, ProductID, Quantity
Products: ProductID, Name, Price
Sample data excerpts (from slides):
Andrei, Toy Duck, 2; Sally, Harry Potter Book, 1; Bruno, Hair Gel, 32
Example query reference link given in slides: https://www.w3schools.com/sql/trysql.asp?
filename=trysqlopin
Data and Documents: XML/JSON representations
XML/JSON-style data examples:
XML:
Mo BinniCanada01/01/1990
JSON-like document example:
{
"EmployeeID": 1,
"FirstName": "John",
"LastName": "Doe",
"Department": {"DepartmentID": 101, "DepartmentName": "HR"}
}
Document databases store data as self-contained documents within collections and often
use JSON-like formats.
References to Practical Data Models and Queries
Five data models with examples:
Relational: tables with rows and columns; SQL; ACID; PK/FK
Document: JSON-like documents; flexible schema
Key-Value: simple key-value pairs; fast access
Graph: nodes, edges, properties; graph queries
Wide Column: column families; distributed storage
Common vendors and databases mentioned:
SQL standards and RDBMSs: MySQL, Oracle, Microsoft SQL Server, PostgreSQL,
MariaDB
Other DBMS and stores: IBM DB2, MongoDB, Elasticsearch, Redis, SQLite,
Cassandra, Neo4j, DynamoDB
Historical context:
SQL invented in the 1970s, originally SEQUEL (Structured English Query Language)
Oracle was among the first commercial SQL-based RDBMS
Codd’s relational model and its rules underpin modern RDBMS design
Practical Design and Data Modeling Elements
Core concepts in relational modeling:
Relation Schema: the definition of a table’s structure, including attribute names
and domains
Degree: number of attributes (columns) in a relation
Cardinality: number of tuples (rows)
Tuple/Row: a single record in a table
Attribute/Column: a data field within a table
Domain/Constraint: allowed values for an attribute
Primary Key: unique identifier for a row
Foreign Key: attribute that references a primary key in another table
Sample table structures derived from slides:
Table: Users with columns id, firstName, lastName, sex, dob, etc.; sample rows with
user data
Important relational terms recap:
Relational model emphasizes tables, keys, and relationships
Degrees and cardinalities describe table structure and data volume
CODD and Relational Rules
The slides reference Codd’s 12 rules and 13 rules of CODD (standards for what constitutes a
relational DBMS).
These rules underpin why relational databases enforce structured schemas, integrity
constraints, and a rigorous data model.
Practical point: Modern RDBMS adhere to these ideas, even as some extend with NoSQL
features.
Examples: SQL Table Creation and Queries (Concrete Snippets)
Create two related tables and join them:
sql CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY, FirstName
VARCHAR(50), LastName VARCHAR(50), DepartmentID INT ); CREATE TABLE
Departments ( DepartmentID INT PRIMARY KEY, DepartmentName
VARCHAR(50) ); INSERT INTO Employees (EmployeeID, FirstName,
LastName, DepartmentID) VALUES (1, 'John', 'Doe', 101), (2, 'Jane',
'Smith', 102); INSERT INTO Departments (DepartmentID,
DepartmentName) VALUES (101, 'HR'), (102, 'Engineering'); SELECT
Employees.FirstName, Employees.LastName, Departments.DepartmentName
FROM Employees JOIN Departments ON Employees.DepartmentID =
Departments.DepartmentID;
Example of an INSERT into a simpler Users table (as shown in slides):
sql CREATE TABLE Users ( fdUserID varchar(10), fdFirstName
varchar(150), fdLastName varchar(150), fdDateOfBirth DATE, fdGender
varchar(1), fdJobTitle varchar(150), PRIMARY KEY (fdUserID) );
INSERT INTO Users (fdUserID, fdFirstName, fdLastName,
fdDateOfBirth, fdGender, fdJobTitle) VALUES ('u1', 'George',
'Jacobson', '1992-01-01', 'm', 'manager'), ('u2', 'Macy',
'Waterson', '1992-01-01', 'f', 'employee'), ('u3', 'Bill',
'Peters', '1992-01-01', 'm', 'employee');
Quick Reference: SQL Statement Structure
SQL Statement anatomy (as shown):
Clause, Identifier, Expression, Keyword, Condition
Example breakdown: SELECT NAME FROM USERS WHERE ROLE = 'MANAGER'
The Database vs File Processing System
A File Processing System reads/writes data in files; traditional approach with limited multi-
user support and querying capabilities.
The database approach provides querying, data security, data integrity, and multi-user
access through DBMS.
The database approach is an advancement over simple file-based storage.
XML/JSON and Semi-Structured Data (Illustrative)
Semi-structured data representations demonstrate flexibility beyond strict schemas:
XML example snippets showing hierarchical data structures
JSON-like snippets showing nested documents (e.g., Department nested under
Employee)
These illustrate why document databases and semi-structured models are useful in modern
data storage scenarios.
Exercises and External Resources Mentioned
Practice resources referenced in slides:
W3Schools SQL TryIt: https://www.w3schools.com/sql/trysql.asp?
filename=trysqlopin
W3Resource SQL basics: https://www.w3resource.com/sql/sql-basic/codd-12-rule-
relation.php
Videos and further reading were suggested for SQL history and fundamentals.
Practical Implications and Takeaways
DBMS vs RDBMS terminology matters for understanding capabilities and data integrity
guarantees.
SQL remains the standard for relational querying, but procedural extensions (e.g., T-SQL,
PL/SQL, PL/pgSQL) introduce imperative features.
Understanding the data models helps in choosing the right storage technology for a given
use case (e.g., graph for relationships, document for flexible schemas, wide column for big
data workloads).
The ACID properties ensure reliable transactions, crucial in multi-user environments.
Practical database design involves careful consideration of schema, keys, constraints, and
normalization to maintain data integrity and query performance.