Skip to content
Computer Aptitude · 1-2 Qs

Database (DBMS)

Read the notes once, then practise. Every question shows the full solution right after you answer.

Study notes

Basics

A database is an organised collection of related data. A DBMS (Database Management System) is software to create, store, retrieve and manage it – e.g. MySQL, Oracle Database, PostgreSQL, Microsoft SQL Server, MS Access. An RDBMS stores data in tables (relations); the relational model was proposed by E. F. Codd in 1970. NoSQL databases such as MongoDB store documents or key-value pairs instead of tables.

Advantages of a DBMS: less redundancy, consistency, data sharing, security, backup and recovery, concurrent access. Metadata (data about data) is kept in the data dictionary.

Relational terms

Formal termCommon term
RelationTable
TupleRow / record
AttributeColumn / field
DegreeNumber of attributes (columns)
CardinalityNumber of tuples (rows)
DomainSet of allowed values for an attribute
SchemaLogical design / structure of the database
InstanceData in the database at a given moment

Keys

KeyMeaning
Super keyAny set of attributes that uniquely identifies a row
Candidate keyMinimal super key; a table may have several
Primary keyCandidate key chosen to identify rows; unique and NOT NULL; one per table
Alternate keyCandidate keys not chosen as primary key
Foreign keyAttribute that refers to the primary key of another table; enforces referential integrity
Composite keyKey made of two or more columns
Unique keyValues must be unique but (in most systems) NULL is allowed

Example: in a bank, Account_No is the primary key of the ACCOUNTS table and appears as a foreign key in the TRANSACTIONS table.

SQL command groups

GroupFull formCommands
DDLData Definition LanguageCREATE, ALTER, DROP, TRUNCATE, RENAME
DMLData Manipulation LanguageINSERT, UPDATE, DELETE (SELECT is often listed here or as DQL)
DCLData Control LanguageGRANT, REVOKE
TCLTransaction Control LanguageCOMMIT, ROLLBACK, SAVEPOINT

DELETE vs TRUNCATE vs DROP

  • DELETE FROM t WHERE ... – removes selected rows; can be rolled back.
  • TRUNCATE TABLE t – removes all rows, keeps the structure.
  • DROP TABLE t – removes the table structure and all its data.

SELECT query order

SELECT columns FROM table WHERE row-condition GROUP BY column HAVING group-condition ORDER BY column ASC|DESC;

  • WHERE filters rows; HAVING filters groups made by GROUP BY.
  • ORDER BY sorts; ascending is the default.
  • DISTINCT removes duplicate rows from the result.
  • Aggregate functions: COUNT, SUM, AVG, MAX, MIN.
  • LIKE patterns: % = any number of characters, _ = exactly one character. 'S%' starts with S; '%S' ends with S.
  • IS NULL tests for missing values (not = NULL).
  • Joins: INNER, LEFT, RIGHT, FULL OUTER combine rows from tables.

Normalisation

Organising tables to reduce redundancy and avoid insertion, update and deletion anomalies.

Normal formRule
1NFEvery column holds atomic (indivisible) values; no repeating groups
2NF1NF + no partial dependency (non-key column depends on the whole composite key)
3NF2NF + no transitive dependency (non-key column depends only on the key)
BCNFStricter 3NF: every determinant is a candidate key

Transactions: ACID

  • Atomicity – all or nothing (a fund transfer debits and credits together or not at all).
  • Consistency – database moves from one valid state to another.
  • Isolation – concurrent transactions do not interfere.
  • Durability – committed changes survive crashes.

Data models and E-R diagrams

Models: hierarchical (tree), network (graph, Charles Bachman), relational (tables, Codd), object-oriented. The E-R model was proposed by Peter Chen (1976). Symbols: rectangle = entity, ellipse = attribute, diamond = relationship, double ellipse = multivalued attribute, underlined attribute = key.

Data warehouse – large store of historical data for analysis; data mining – finding patterns in it; data mart – subset for one department.

Exam tip: Degree = columns, cardinality = rows. Primary key: unique + not null. WHERE before grouping, HAVING after grouping.
Free SBI Clerk practice with solutionsStart free →