What the database promises
Two theatre buyers can act on the same stale availability. A DBMS coordinates shared rules and accepted changes. Separate its data model, interfaces, concurrency, and recovery responsibilities.
#Section 1A DBMS instead of a collection of files
Asha and Bharat both see theatre seat A7 as available. The database must admit only one claim, even before either browser sees the other buyer’s action.
Imagine storing the inventory in a text file. Each worker opens the file, finds A7 marked free, and writes a reservation. If the workers read before either writes, both decisions use the same old state. Locking only the final file write prevents damaged bytes but does not necessarily prevent the stale decisions: the second worker may patiently wait and then write the reservation it already decided to accept. The entire read-decide-write operation needs coordination.
A database management system, or DBMS, controls storing, querying, and changing data. The database is the managed collection of facts. Diagnose plans, storage, waits, and application use separately rather than blaming the rows themselves.
What the missing control must do
Start from a single inventory fact: A7 is free. Asha requests a transition to held. The authority checks that the current state is still free, admits the transition and records Asha as the owner. Bharat’s later request finds held rather than free and fails. Checking and changing must be one indivisible admission operation, or another buyer can enter between them. Later parts show how a conditional UPDATE, row locks and constraints provide that guarantee.
After acknowledging commit, preserve enough durable evidence to reconstruct the booking after a crash. An unfinished operation must not reappear as a successful purchase. Recovery and concurrent admission solve different problems.
The DBMS also checks that Asha is a real customer and A7 is a real seat in the intended show. It finds bookings without making every client scan every byte. It controls which role may read personal data or change inventory. Those jobs share a reason: every application must use the same authoritative rules, including a future script that the original web developer never anticipated.
Files and the guarantees above them
A DBMS commonly stores persistent data in files too. The useful comparison is the set of guarantees supplied above those files. A filesystem provides names, permissions, block allocation and its own persistence rules. It does not know what a booking is, how seat identity includes a show, or why two active owners would be invalid. You can implement those rules over files, but then your application owns their locking, query structures and recovery log.
Files are often sufficient for an immutable export, a configuration file or a single-writer interchange format. The cost changes when there are competing writers, relationships, indexed searches and multi-record operations. Using a DBMS shares tested machinery across those requirements; it does not excuse an incorrect business rule or eliminate the need to choose the right transaction boundary.
A relational DBMS, or RDBMS, uses relations as its logical data model. DBMS is the wider category: document, key-value and graph engines also manage databases. SQL is a query language associated with many relational engines, but “supports SQL” and “has a relational model” are not identical claims. We begin with relational systems because their explicit dependencies, constraints and transactions make the booking example easy to reason about.
#Section 2Architecture, schemas and independence
An index should speed Heron’s email lookup without changing its meaning. Separating data meaning from byte layout lets storage change without rewriting every caller.
A schema describes data structures and rules. An instance is the data in those structures at a particular moment. Creating users(id, email) changes the schema; inserting Asha changes the instance. A table can keep the same schema while its instance grows, and a schema migration can change structures while retaining most of the existing facts.
The physical level describes pages, files and access paths. The logical level describes relations, attributes and relationships. The view level presents a chosen interface to a user. A view is a named query that exposes such an interface; it can omit attributes or combine facts without requiring the user to understand every base table.
Follow one availability request through the levels
The customer interface asks for available seat codes in a show. Its view may expose only show_id, seat_id and price, leaving internal version or maintenance fields hidden. At the logical level, the view refers to show_seats and a predicate over state. At the physical level, an index may locate the show’s rows and the buffer pool may already hold the corresponding pages.
Replace the physical scan with an index lookup. The rows promised by the query remain the same. This is physical data independence: changing storage does not require changing the logical meaning presented to the application. It has limits in performance and operational behaviour, but the interface should not depend on record byte offsets.
Now split an old users table into identity and profile tables while preserving a view with the old columns. Existing readers can keep using that view. This illustrates logical data independence, where an external interface can survive some logical schema changes. It is harder to provide: dropping information a client genuinely needs cannot be hidden by renaming a table. Updates through the compatibility view may also need explicit rules.
Client and engine responsibilities
An embedded engine runs within its application; a server engine coordinates remote clients. Either way, database constraints must protect every writer, not only the website’s validation path.
Inside the engine, request handling checks the statement, planning chooses operators, execution asks storage for records, and storage uses cached or persistent pages. These are responsibilities, not a promise that every product assigns each to one separate process. PostgreSQL’s concrete process model appears near the end, after we know what the components have to do.
| Command family | Job | Examples |
|---|---|---|
| DDL, data definition | Change structures | CREATE, ALTER, DROP |
| DML, data manipulation | Read or change rows | SELECT, INSERT, UPDATE, DELETE |
| DCL, data control | Set privileges | GRANT, REVOKE |
| TCL, transaction control | Set a transaction boundary | BEGIN, COMMIT, ROLLBACK |
These categories organize the interface rather than describe different storage engines. Some curricula call SELECT data query language separately; explain its job instead of arguing over the teaching label. A database administrator manages operation and access, a designer defines the schema, an application programmer defines workflows, and reporting users read selected facts. Database roles encode which actions each is allowed to take.
#Section 3The relational model, NULL and constraints
The same physical seat can exist in several shows. Within one show, its identity must admit only one valid current state.
A relation is a set of tuples described by attributes. A tuple is a row. An attribute is a named column. A domain is the set of permitted values for an attribute. A seat-state domain might admit free, held and sold, while a price domain admits the chosen numeric representation. Domains describe meaningful values, not merely how many bytes a programming language allocates.
A relation’s degree is its number of attributes. Its cardinality is its number of tuples. The printed projection below has degree 3 and cardinality 3. Heron’s full inventory has 8 shows with 100 seats each, so its cardinality is . Read that multiplication as “one inventory row for every show-seat pair.” The number of columns does not grow merely because another show is added.
Set semantics and SQL’s differences
A mathematical relation has no duplicate tuples and no intrinsic row order. Its attributes identify their meanings, so a printed arrangement is only a presentation. A database can store the rows in any arrangement that supports its operations. An index’s order is an access path, not automatically the result order promised to a query.
SQL usually uses bag semantics, which preserve duplicate results unless the query removes them. Asha has two bookings priced at 120. SELECT price FROM bookings legitimately returns 120 twice, because two rows contribute that value. SELECT DISTINCT price FROM bookings returns the distinct values 120 and 80, without promising their order. ORDER BY price adds an order guarantee. Sorting and removing duplicates are separate operations.
A table may also contain duplicate entire rows unless its constraints prevent them. That is why the relational ideal and an unconstrained SQL table are not interchangeable. We should declare the identifying attributes rather than assume a familiar table shape enforces them. Section 4 makes this identity argument precise with candidate and primary keys.
Missing is not zero or an empty string
NULL represents an absent or unknown value outside ordinary comparison semantics. Suppose Heron has not yet recorded a payment reference. An empty string is a known string of zero length; zero is a known numeric value; NULL says that the reference is absent or unknown. Substituting one for another changes what the data claims.
Comparisons with NULL normally produce UNKNOWN. payment_ref = NULL therefore does not find missing references. payment_ref IS NULL tests the absence explicitly. A WHERE clause keeps TRUE conditions and discards both FALSE and UNKNOWN. This explains why a query can drop a row with a missing value even when the programmer thinks the negated comparison “must be true.”
NULL also affects aggregates and joins. COUNT(*) counts rows, while COUNT(payment_ref) counts present references. An outer join uses NULL to extend an unmatched side, which is not the same as proving that a real matched row had a missing field. SQL’s later sections work these cases through against actual input and output rows.
A constraint rejects illegal database state. Keys, references, and value checks protect different invariants. Cross-row totals or capacity rules can also require transaction-aware coordination.