Database Management Systems and SQL
Database Management Systems and SQL
This domain tests data organisation and querying: keys, relationships, normalization ideas, and SQL for defining and manipulating tables. Expect short queries and questions on constraints and NULL behaviour.
Core rules
- A primary key uniquely identifies each row and cannot be NULL. A foreign key references a primary key in another table.
- SQL categories: DDL (
CREATE,ALTER,DROP), DML (INSERT,UPDATE,DELETE), DQL (SELECT), DCL (GRANT,REVOKE). SELECTchooses columns;WHEREfilters rows;ORDER BYsorts;GROUP BYgroups for aggregates.DISTINCTremoves duplicate result rows.NULLis unknown, so test it withIS NULL, not= NULL.- Normalization reduces redundancy and update anomalies by organising attributes into related tables.
Worked example
Table Student(roll, name, mark). Query: SELECT name FROM Student WHERE mark >= 60 ORDER BY name;. The reasoning: SELECT name limits output to one column; WHERE mark >= 60 keeps qualifying rows; ORDER BY name sorts alphabetically. If duplicates were possible in a different query, SELECT DISTINCT would remove them.
Traps
DELETE removes rows but keeps the table; DROP removes the table structure. String literals need single quotes. WHERE mark = NULL returns no rows; use IS NULL. Aggregate functions ignore NULLs in many systems. A foreign key must match an existing referenced value unless NULL is allowed. Do not confuse a candidate key with the chosen primary key.