This chapter provides a comprehensive introduction to Database Management Systems (DBMS), focusing on Relational Database Management Systems (RDBMS) and the use of Structured Query Language (SQL) with MySQL. Below is a structured summary of the key concepts covered in the chapter.
Data vs. Information: Data is raw, unorganized facts and figures (e.g., numbers or names without context). Information is data processed, formatted, and structured in a meaningful way to aid decision-making.
The DIKW Model: The chapter introduces the Data, Information, Knowledge, and Wisdom hierarchy to illustrate how raw input transforms into actionable understanding.
Database Elements:
Table: A collection of related data held in a structured format.
Record (Row/Tuple): A horizontal entry representing a single, complete unit of data (e.g., one student's details).
Field (Column/Attribute): A vertical entry representing a single piece of data of a specific type (e.g., Age, Name).
Instance vs. Schema: The schema is the overall design or structural blueprint of the database, whereas an instance is the actual collection of data stored in the database at any specific moment.
Traditional File System Limitations: Historically, organizations stored data in independent flat files. This led to severe issues, including:
Data Redundancy and Inconsistency: Duplication of data across departments, leading to conflicting records when updates were made.
Application Dependency: Programs were tightly coupled with specific file structures.
Lack of Security and Data Sharing: Difficult to enforce universal security access controls and share data concurrently.
Atomicity & Concurrency Issues: Lack of structural mechanisms (ACID properties) to ensure transactions completed successfully or failed entirely without corrupting files.
Advantages of DBMS: Reduces redundancy, enforces data consistency, supports complex data integration, facilitates concurrent multi-user access, secures access privileges, and provides robust backup and recovery solutions.
Disadvantages of DBMS: High initial setup costs (hardware, software, trained staff), added system complexity, slower execution speeds compared to direct flat files, and massive disk storage requirements.
The DBMS uses three distinct levels of abstraction to hide technical complexity from different users:
Internal (Physical) Level: Defines how the data is physically stored on disk storage devices, describing physical paths, compression, and encryption.
Conceptual (Logical) Level: Describes the structure of the entire database, defining what data is stored, their relationships, and logical constraints. It is maintained by the Database Administrator (DBA).
External (View) Level: The closest level to the users. It provides customized, limited views of the database to different users, hiding irrelevant database elements.
Key Users:
Application Programmers: Write code (COBOL, Java, C++) to interface with the database.
End Users: Direct users (who interact directly, like railway ticket agents) and indirect users (who benefit from reports generated by programs).
System Analysts: Determine user requirements and plan the database design.
Database Administrator (DBA): The person who makes strategic decisions and exercises overall control. DBA duties include schema definition, storage structure design, access authorization, performance monitoring, and backup/recovery.
Data Dictionary: A repository containing metadata (data about data).
Active Data Dictionary: Automatically updated by the DBMS whenever DDL changes occur.
Passive Data Dictionary: Created separately and must be modified manually to stay in sync.
To enforce data quality and ensure relationships remain accurate, relational databases rely on:
Integrity Constraints:
Domain Constraint: Restricts values in a column to a specific range or data type (e.g., Age must be a positive integer).
Entity Integrity Constraint: States that a Primary Key column cannot contain null values.
Referential Integrity Constraint: Ensures a Foreign Key in one table matches a Primary Key value in another table, preventing orphaned records.
Key Constraint: Assures that each record is uniquely identifiable.
Types of Relational Keys:
Super Key: A set of one or more columns that uniquely identifies a row.
Candidate Key: Minimal Super Keys that can serve as the primary identifier.
Primary Key: The chosen Candidate Key used to uniquely identify each row (cannot be null).
Alternate Key: Candidate Keys not chosen as the Primary Key.
Unique Key: Similar to a primary key but allows a single NULL value.
Composite Key: A key composed of more than one column.
Foreign Key: A column that links a record to the primary key of another table.
SQL is the standard language used to perform operations on relational databases. MySQL supports three primary data types: Numeric (int, decimal), Date/Time (date, time), and String (fixed-length char vs. variable-length varchar).
SQL commands are grouped into four main sub-languages:
DDL (Data Definition Language): Defines and alters the database structure.
CREATE DATABASE, CREATE TABLE, ALTER TABLE (ADD, DROP, MODIFY), DROP TABLE, TRUNCATE TABLE (deletes records but retains structure).
DML (Data Manipulation Language): Handles data entry and retrieval.
INSERT INTO, UPDATE, DELETE FROM, and SELECT (supports clauses like WHERE, ORDER BY, DISTINCT, and operators like BETWEEN, LIKE with wildcards %, and IN).
TCL (Transaction Control Language): Manages database transactions to ensure consistency.
COMMIT (saves changes), ROLLBACK (undoes changes), SAVEPOINT (marks a point to roll back to), and SET TRANSACTION.
DCL (Data Control Language): Controls database security and privileges.
GRANT (gives user access) and REVOKE (takes away access privileges).
Aggregate Functions (Multiple input rows, single output):
AVG(): Calculates the average value of a column.
COUNT(): Counts the number of rows.
FIRST() / LAST(): Returns the first/last value of a column.
MAX() / MIN(): Finds the highest/lowest value.
SUM(): Adds the numerical values of a column.
Scalar Functions (Single input value, single output):
UCASE() / LCASE(): Converts text to uppercase/lowercase.
MID(): Extracts characters from a text field.
LEN(): Returns the length of a string.
ROUND(): Rounds a numeric value to specified decimals.
NOW(): Returns the current system date and time.