Databases & DBMS — Study Notes
What to learn in Databases & DBMS
This topic is databases the way the one-paper exams ask them: not theory for its own sake, but the facts that decide which option is right. There are 178 practice questions on this page: 130 from the bank and 48 new ones written to fill the gaps the bank leaves — most of them in the ER model, normalisation and transactions, which the bank covers thinly. The bank itself repeats the same facts many times in different words (the primary key is asked ten ways, the view six ways), so the repeats have been cut down to one best copy each — 124 rewordings removed, all listed in the batch moves file, none deleted from the bank. The order below is the order to learn in. Start with DBMS basics, because every later branch talks about tables, rows, fields and keys. Then the ER model, because it is how you draw a database before you build it. Then the relational model, because it gives you the keys and the integrity rules. Then SQL, the language you talk to the database in. Then normalisation, which is the design discipline that keeps one fact in one place. Then transactions, which are how a database survives crashes and many users at once. Past papers — PPSC, FPSC, BPSC, KPPSC, NTS, STS and ETEA — ask the same core facts again and again: the full form of DBMS, the primary key, the foreign key, 2NF against 3NF, SELECT against INSERT, COMMIT against ROLLBACK. Learn each fact once, then practise it until the right option feels obvious. Two boundary notes. First, Microsoft Access appears here as a database system — its tables, forms, reports and file extension — while the MS Office topic covers the office tools as applications. Second, the electronic record-keeping and data-governance questions stay on this page: there is no record-keeping topic in the tree, and they belong with databases more than anywhere else. One trap to learn early: three past papers ask the same 'repository for data covering a specific topic' question and answer it three different ways. The answer kept on this page is Databank — it is the copy where both Database and Databank are options, and it matches the standard definition of a databank as a repository of information on a specific subject.
DBMS basics: what a database is and who looks after it
A database is an organised collection of related data, and a DBMS — a Database Management System — is the software that creates it, stores data in it, reads it, changes it and deletes from it. Without the DBMS there is only a pile of files; the DBMS is what gives you tables, queries, users and safety. Learn the vocabulary of a table first, because every later branch uses it: a table is a collection of related records in rows and columns, a record (a row, a tuple) is one complete entry, a field (a column, an attribute) is one piece of information about that record, and the smallest logical unit of data is the field. The schema is the design of the whole database — its tables, fields and relationships — and the data dictionary is the store that holds the definitions of all of them. The person in charge is the database administrator, the DBA, whose job is managing and securing the database system; the software component that does the actual storing and querying is the database engine. Then learn the systems by name, because the papers love asking which one is which: Oracle, MySQL and PostgreSQL are relational systems, PostgreSQL is the open-source one, Microsoft Access is the desktop database system whose files end in .accdb and which arranges its data in tables with forms for entry and reports for printing, and MongoDB is the document NoSQL database for unstructured data. A data warehouse is the big central store of historical data from many sources, kept for reporting rather than daily transactions; a databank is a repository of data on a specific topic; and data governance is the organisation's capability to ensure high-quality data. The older models matter too: the hierarchical model organises data as a tree of parent and child records, the network model lets a record have more than one parent, and the three-schema architecture splits the database into the external view one user sees, the conceptual logical structure, and the internal physical storage. Physical data independence is the promise that the storage underneath can change without changing the tables above it.
The vocabulary of a table
- Database — an organised collection of related data.
- Table (relation) — a collection of related records in rows and columns.
- Record (row, tuple) — one complete entry, such as one student.
- Field (column, attribute) — one piece of information about a record, such as a name.
- Schema — the design of the database: its tables, fields and relationships.
- Data dictionary — the central store of definitions of the data elements, tables and fields.
Database systems you must know
- Oracle — commercial relational database management system.
- MySQL — widely used relational system, the usual example of a DBMS.
- PostgreSQL — open-source relational database management system.
- Microsoft Access — desktop DBMS; files end in .accdb; forms enter data, reports print it.
- MongoDB — popular document-oriented NoSQL database for unstructured data.
Data types
- Text — letters and words.
- Date & Time — a value such as 01-01-2020 11:30.
- String — text data, such as a person's address.
The ER model: draw the database before you build it
The Entity-Relationship model, proposed by Peter Chen in 1976, is the drawing you make before you build anything. It has only three building blocks, and the papers test them constantly: an entity is a real-world object about which data is stored, such as a student or an employee; an attribute is a property or characteristic of an entity, such as a student's name or age; and a relationship links entities, such as a student enrols in a course. In the diagram an entity is a rectangle, an attribute is an ellipse and a relationship is a diamond — that one symbol question comes up again and again. Attributes come in kinds, and each kind has its own drawing: a simple attribute cannot be split, a composite attribute divides into parts (a name into first and last name), a single-valued attribute holds one value, a multi-valued attribute holds several and is drawn as a double ellipse, a stored attribute is kept as it is, a derived attribute is worked out from another — age from date of birth — and is drawn as a dashed ellipse, and a key attribute is underlined. Cardinality says how many instances of one entity relate to another: one-to-one, one-to-many, many-to-one or many-to-many. Participation says whether every entity must take part (total, drawn with a double line) or only some may (partial, a single line). A weak entity has no key of its own and cannot exist without its owner entity — a dependent of an employee is the classic example — and it is drawn as a double rectangle. Then comes the step the papers love most: turning the drawing into tables. A one-to-many relationship needs no new table: the primary key of the 'one' side goes as a foreign key on the 'many' side. A many-to-many relationship needs a new table of its own, holding both primary keys together — an Enrolment table holding student_id and course_id. Learn the symbols as one picture and the conversion as two rules, and the whole branch falls into place.
ER diagram symbols
- Rectangle — entity (double rectangle — weak entity).
- Ellipse — attribute (double ellipse — multi-valued; dashed ellipse — derived; underlined — key).
- Diamond — relationship (double diamond — the identifying relationship of a weak entity).
- Single line — partial participation; double line — total participation.
Attribute kinds
- Simple — cannot be split; composite — divides into parts, such as name into first and last name.
- Single-valued — one value; multi-valued — several values, such as phone numbers.
- Stored — kept as it is; derived — calculated from another attribute, such as age from date of birth.
- Key — uniquely identifies the entity.
Cardinality and participation
- Cardinality — how many instances of one entity relate to another: 1:1, 1:N, N:1, M:N.
- Total participation — every entity must take part; partial participation — some may not.
- Degree — the number of entity sets in a relationship: unary (1), binary (2), ternary (3).
The relational model: tables, keys and the rules that keep them honest
The relational model stores data in tables — relations — of rows and columns. A row is a tuple, a column is an attribute, a table is also called a relation, and the model that organises data this way is the relational model, run by a relational database management system, an RDBMS. The whole branch turns on keys, so learn them as a ladder, smallest to largest. A super key is any set of columns that uniquely identifies each row. A candidate key is a minimal super key — no column can be removed from it. The primary key is the candidate key the designer chooses: one per table, unique and never null, and it may be a composite key of more than one column. A candidate key not chosen becomes an alternate key. A foreign key is a column in one table that refers to the primary key of another table, and it is what links tables together — it may repeat and it may be null, which is exactly how a primary key differs from it. Two rules then guard the whole model. Entity integrity says no part of a primary key may be null, because a null value could not identify a row — and, by the same rule, no two rows may share the same primary key. Referential integrity says a foreign key value must either be null or match a primary key value in the referenced table, so that no row points at a record that does not exist. Learn the ladder and the two rules together: the keys are the mechanism, the rules are the promise. Two more words complete the vocabulary. A domain is the set of permitted values for an attribute — the marks column might allow only whole numbers from 0 to 100. The degree of a relation is its number of attributes and its cardinality is its number of tuples — do not confuse this cardinality with the cardinality of an ER relationship, which is about how many instances relate.
The keys, smallest to largest
- Super key — any set of columns that uniquely identifies each row.
- Candidate key — a minimal super key; a table can have several.
- Primary key — the chosen candidate key; unique, never null; only one per table; may be composite.
- Alternate key — a candidate key not chosen as the primary key.
- Foreign key — refers to the primary key of another table; links tables; may repeat and may be null.
- Composite key — a key made of more than one attribute.
The integrity rules
- Entity integrity — no part of a primary key may be null; no two rows share the same primary key.
- Referential integrity — a foreign key must be null or match an existing primary key in the referenced table.
Relation words
- Relation — a table; tuple — a row; attribute — a column; domain — the permitted values of an attribute.
- Degree of a relation — its number of attributes; cardinality of a relation — its number of tuples.
SQL: the language you talk to the database in
SQL — Structured Query Language, developed at IBM — is the standard language for relational databases, and the papers test it in two ways: which command does what, and which family the command belongs to. Learn the five families as one table. DDL, the Data Definition Language, defines structure: CREATE, ALTER, DROP and TRUNCATE. DML, the Data Manipulation Language, changes the data: INSERT adds a row, UPDATE changes values already stored, DELETE removes rows. DQL, the Data Query Language, has one command, SELECT, which reads data. DCL, the Data Control Language, controls access: GRANT gives a privilege and REVOKE takes it back. TCL, the Transaction Control Language, manages transactions: COMMIT, ROLLBACK and SAVEPOINT. Three distinctions inside DDL catch students out, so learn them as a set: DELETE removes rows (with a WHERE clause, logged row by row, and roll-backable), DROP TABLE removes the table and its data permanently, and TRUNCATE TABLE removes all rows but keeps the structure. A query is a request to retrieve specific data, and its clauses work in a fixed order: SELECT the columns, FROM the table, WHERE to filter rows, GROUP BY to group them, HAVING to filter the groups (HAVING is WHERE for groups — the papers ask this difference directly), ORDER BY to sort the result, and DISTINCT to drop duplicate values from the result. The aggregate functions sit on top of grouping: COUNT counts rows, SUM totals a numeric column, AVG averages it, MAX takes the largest value and MIN the smallest. Joins combine rows from two tables on a related column: INNER JOIN returns only rows that match in both tables, LEFT JOIN returns all rows from the left table with NULL where there is no match, RIGHT JOIN the mirror image, FULL OUTER JOIN all rows from both tables, and CROSS JOIN the Cartesian product of the two. UNION combines two query results and removes duplicates; UNION ALL keeps them. The LIKE operator matches patterns, with % for any number of characters. Finally the four objects SQL creates: a view is a virtual table made from a query, showing data without storing it; an index speeds up finding rows without scanning the whole table; a trigger runs automatically when an event such as an INSERT happens on a table; and a stored procedure is a saved set of SQL statements run by name. In MS Access the same ideas appear with different wildcards — ? matches exactly one character, so S???? is a five-letter word starting with S — and a form is the screen for entering data while a report presents it for printing.
The five families of SQL commands
- DDL — Data Definition Language: CREATE, ALTER, DROP, TRUNCATE.
- DML — Data Manipulation Language: INSERT, UPDATE, DELETE.
- DQL — Data Query Language: SELECT.
- DCL — Data Control Language: GRANT, REVOKE.
- TCL — Transaction Control Language: COMMIT, ROLLBACK, SAVEPOINT.
The clauses in order
- SELECT — pick the columns; FROM — pick the tables.
- WHERE — filter rows; GROUP BY — group rows that share values.
- HAVING — filter groups after aggregation; ORDER BY — sort the result.
- DISTINCT — remove duplicate values from the result.
The joins
- INNER JOIN — only rows that match in both tables.
- LEFT JOIN — all rows from the left table, NULL where there is no match.
- RIGHT JOIN — all rows from the right table, NULL where there is no match.
- FULL OUTER JOIN — all rows from both tables; CROSS JOIN — the Cartesian product.
Objects SQL creates
- View — a virtual table made from a query; it stores no data itself.
- Index — speeds up finding rows without scanning the whole table.
- Trigger — runs automatically when an event such as an INSERT occurs.
- Stored procedure — a saved set of SQL statements, run by name.
Normalisation: one fact in one place
Normalisation is the design discipline of organising data into related tables so that each fact lives in exactly one place. Its purpose is to reduce data redundancy — the same data stored in more than one place — and with it the three anomalies that redundancy causes. An insertion anomaly means you cannot store one fact without storing another: you cannot add a new department until it has an employee, because both facts live in the same row. A deletion anomaly means deleting a row destroys facts that should survive: deleting the last employee of a department deletes the department itself. An update anomaly means one fact lives in many rows, so changing it means changing every copy, and any copy missed leaves the database contradicting itself. The cure is the normal forms, and they are defined by functional dependencies. A functional dependency X → Y means knowing X tells you Y: if you know the student_id, you know the student's name. A partial dependency is a fact that depends on only part of a composite key, and a transitive dependency is a non-key fact that depends on another non-key fact instead of directly on the key. Then the forms follow in order, and the mnemonic to carry is 'the key, the whole key, and nothing but the key'. First Normal Form requires atomic values — one value per cell, no repeating groups. Second Normal Form is 1NF with no partial dependency: every non-key column depends on the whole primary key. Third Normal Form is 2NF with no transitive dependency: every non-key column depends on the key and on nothing but the key. Boyce-Codd Normal Form is stricter than 3NF: every determinant — the left side of any functional dependency — must be a superkey. Fourth Normal Form removes multi-valued dependencies, where two independent multi-valued facts share a table, and Fifth Normal Form removes join dependencies. In practice 3NF or BCNF is the target for most databases. Going the other way has a name too: denormalisation deliberately adds back controlled redundancy to avoid joins and speed up reads, accepting slower writes and some update risk.
The normal forms
- 1NF — atomic values; no repeating groups.
- 2NF — 1NF plus no partial dependency on part of a composite key.
- 3NF — 2NF plus no transitive dependency between non-key attributes.
- BCNF — every determinant is a superkey; stricter than 3NF.
- 4NF — BCNF plus no multi-valued dependency; 5NF — no join dependency.
The three anomalies
- Insertion anomaly — one fact cannot be stored without another.
- Deletion anomaly — deleting a row destroys facts that should survive.
- Update anomaly — one fact in many rows must be changed everywhere, or copies disagree.
Dependencies
- Functional dependency X → Y — knowing X tells you Y.
- Partial dependency — a fact depends on only part of a composite key.
- Transitive dependency — a non-key fact depends on another non-key fact.
Transactions: all or nothing
A transaction is a single unit of work that must complete fully or not at all — the classic example is moving money between two accounts, where taking it from one and giving it to the other must happen together or not at all. Its four promises spell ACID. Atomicity: all or nothing, never half-done. Consistency: the transaction moves the database from one valid state to another, with every declared rule — keys, foreign keys, NOT NULL, CHECK — still holding at the end. Isolation: each transaction behaves as if it ran alone, so concurrent transactions cannot trip over each other. Durability: once a transaction has committed, its effects survive a crash. The commands are three. COMMIT saves all changes made by the transaction permanently. ROLLBACK undoes them all. SAVEPOINT marks a point inside the transaction to roll back to without undoing the whole thing. After its last operation a transaction is partially committed — the work is done but not yet permanent — and COMMIT moves it to committed, while a failure before that moves it to failed and then aborted after rollback. When many users share one database, concurrency control is what stops their transactions conflicting. Locks are its tool: a shared lock lets many transactions read a row but none change it, while an exclusive lock gives one transaction sole access until it is released. When two transactions each hold a lock the other needs, neither can move — that is a deadlock, and the DBMS breaks it by aborting one of them. Optimistic locking, which holds no locks and checks at commit time, is the strategy that minimises deadlocks. The isolation levels run from weakest to strongest: READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ and SERIALIZABLE, which makes concurrent transactions behave exactly as if they ran one after another. And if the worst happens, recovery is possible because a log file records every change, and a regular database backup copies data to a safe place so it can be restored after a crash or an attack.
ACID — the four promises
- Atomicity — all or nothing, never half-done.
- Consistency — from one valid state to another; every declared rule still holds.
- Isolation — each transaction behaves as if it ran alone.
- Durability — once committed, the effects survive a crash.
The transaction commands
- COMMIT — save all changes permanently.
- ROLLBACK — undo all changes made by the current transaction.
- SAVEPOINT — mark a point to roll back to without undoing the whole transaction.
When many users share one database
- Concurrency control — prevents conflicts when several users access data at once.
- Shared lock — many may read, none may change; exclusive lock — sole access until released.
- Deadlock — two transactions waiting forever for each other's locks.
- Isolation levels, weakest to strongest — READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE.
- Log file — records changes so the database can be restored; backup — copies data to a safe place.
More facts to learn
- Which of the following enhances query performance by dividing large tables into smaller onesPartitioning
- Which of the following is an example of a databaseA list of contacts stored in a phone
- In a Database table, a single row will be calledRecord
- What does RDBMS stand forRelational Database Management System
- What is an attribute in a database tableA column of the table
- Which of the following is the main responsibility of a Database Administrator (DBA)Managing and securing the database system
- In Microsoft Access, a report is mainly used to:Present database data in a printed format
- Which central store holds definitions and descriptions of the data elements, tables and fields in a databaseData dictionary
- Which commercial relational database management system is developed by the Oracle CorporationOracle Database
- Which software manages databases and lets users create, read, update and delete dataDatabase Management System (DBMS)
- The smallest logical unit of data in a database is aField
- What does DBMS stand forDatabase management system
- What is the significance of classification in record managementOrganized a systematic retrieval
- What is the main purpose of electronic record keepingPermanent Files
- MS Access arranges data in:Tables
- Which software is commonly used for database managementMySQL
- MS Access is which type of softwareDatabase
- A weak entity in an ER model is an entity that:Cannot exist without its owner entity
- Which diagram shows entities, their attributes and the relationships between them in a database designEntity-Relationship diagram
- Which of the following is a relational databaseOracle
- Which property must a primary key always haveUnique and not null
- Which field in a database table uniquely identifies each record, with no two records sharing the same valuePrimary key
- Which database model stores data in tables made of rows and columnsRelational model
- Primary key is aAll of these
- Oracle is an example of which type of softwareRelational database management system
- What does 'DDL' stand for in database workData Definition Language
- SQL stands for:Structured Query Language
- In SQL, the Data Manipulation Language (DML) includes which of the following commandsINSERT
- A LEFT JOIN returns all rows from the left table and:Matching rows from the right table, with NULL where there is no match
- A CROSS JOIN between two tables produces:The Cartesian product of the two tables
- In SQL, the HAVING clause differs from WHERE because HAVING filters:Groups after aggregation
- Which database request asks the system to retrieve specific information, for example all customers from one cityQuery
- Which SQL statement is used to retrieve data from one or more tables in a databaseSELECT
- Which saved set of SQL statements is stored in the database and can be executed by calling its nameStored procedure
- Which SQL statement adds a new row to a tableINSERT
- Which SQL statement permanently removes a table and its dataDROP TABLE
- Which SQL clause sorts the result of a queryORDER BY clause
- In MS Access, if you want to search for a word that is exactly 5 characters long and starts with "S", the pattern you would use is:S????
- Storing same data on multiple locations is called:Redundancy
- Which normal form requires a table to be in 1NF with no partial dependency on a composite keySecond Normal Form (2NF)
- Which locking strategy is most effective at minimizing the occurrence of deadlocksOptimistic
- Which SQL command undoes all changes made by the current transactionROLLBACK
- Which regular practice copies database data to a safe location so that it can be restored after a crash or attackDatabase backup
- What is a transaction in a databaseA single unit of work that must complete fully or not at all
- In the three-schema architecture of a database, the conceptual schema describes:The logical structure of the whole database
- In an ER diagram, a multi-valued attribute is drawn as a:Double ellipse
- A relationship in which three entity sets take part is called a:Ternary relationship
- When an ER diagram with a many-to-many relationship is converted into tables, the relationship is stored in:A new separate table holding both primary keys
- A super key in a relational table is:Any set of columns that uniquely identifies each row
- The entity integrity rule of the relational model states that:No part of a primary key may be null
- The degree of a relation is the number of:Attributes (columns) of the table
- Which SQL command takes back a privilege that was given with GRANTREVOKE
- Which SQL aggregate function returns the largest value in a columnMAX
- In SQL, the LIKE operator is used with which wildcard to match any number of characters %
- A functional dependency X Y means that:Knowing X tells you Y. An update anomaly is a problem in which: Changing one fact means changing it in many places and some copies may be missed
- Boyce-Codd Normal Form requires that every determinant (the left side of a functional dependency) must be:A superkey
- In the ACID properties, the letter I stands for:Isolation
- A shared lock on a row allows other transactions to:Read the row but not change it
- A transaction that has finished its operations but has not yet committed is in which statePartially committed