Sub topic 3
RDBMS Software and the SQL Language
This chapter assumes you understand basic tabular data and can read short code examples. It also assumes you know that an application may need to save data after it stops running. You do not need to know a specific database product.
What an RDBMS does
An RDBMS, or relational database management system, is software that stores and manages relational data. PostgreSQL, MySQL, MariaDB, Microsoft SQL Server, Oracle Database, and SQLite are examples.
The word management matters. An RDBMS does more than save files. It:
- Stores data in tables.
- Checks rules such as required values and unique identifiers.
- Finds rows efficiently.
- Allows several users or application processes to work with data.
- Protects grouped changes with transactions.
- Controls access to data.
- Recovers data after certain failures.
A relational database describes data through tables and relationships between tables. The RDBMS implements that model. It stores the data, interprets requests, and decides how to execute them.
| Part | Responsibility |
|---|---|
| Relational model | Describes data as related tables |
| RDBMS | Stores data and enforces database behavior |
| SQL | Expresses operations on the data |
SQL is the database language
SQL, or Structured Query Language, is used to define, read, change, and control relational data. SQL is mostly declarative. You state the result or operation you want, and the RDBMS chooses the steps needed to produce it.
For example, a SELECT statement asks for matching rows. You do not normally specify whether the database should scan a table or use an index. The database optimizer chooses an execution plan.
SQL statements are often grouped by purpose:
- DDL, or data definition language, creates and changes structures. Examples include
CREATE TABLEandALTER TABLE. - DML, or data manipulation language, reads and changes rows. Examples include
SELECT,INSERT,UPDATE, andDELETE. - DCL, or data control language, manages permissions. Examples include
GRANTandREVOKE. - Transaction statements include
BEGIN,COMMIT, andROLLBACK.
The exact SQL features vary between products. A query that works in PostgreSQL may require changes in SQLite or SQL Server. The core ideas remain similar.
A small working example
The following script uses SQLite syntax. It creates a table, adds rows, and reads selected columns.
CREATE TABLE customers (
customer_id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE
);
INSERT INTO customers (customer_id, name, email)
VALUES
(1, 'Ada Lovelace', '[email protected]'),
(2, 'Grace Hopper', '[email protected]');
SELECT customer_id, name
FROM customers
WHERE customer_id = 1;CREATE TABLE defines the table's schema. The schema is the formal description of its columns, data types, and rules.
INSERT adds rows. Listing the column names makes the statement clearer and prevents errors if the table later gains another column.
SELECT reads data. FROM identifies the table, and WHERE filters the rows. The result contains Ada's identifier and name.
The RDBMS checks the constraints while executing the statements. For example, inserting a second row with customer_id = 1 would violate the primary key. Inserting a customer without an email would violate NOT NULL.
Product differences and common errors
An RDBMS may accept standard SQL while adding its own features. Differences commonly appear in date functions, auto-generated keys, string concatenation, pagination, and transaction behavior.
A common error is confusing SQL with the database itself. SQL is the language used to communicate with an RDBMS. Another error is assuming that a successful statement means the data is correct. Constraints, transactions, and application validation work together to protect correctness.
Exercise
What is the difference between an RDBMS and SQL?
Show answer
An RDBMS is the software that stores and manages relational data. SQL is the language used to define, read, change, and control that data.