Database Security MCQs for NSCT
Database security decides who may read or change which data, and stops attackers from getting around those rules. In SQL that means authorisation with GRANT and REVOKE, plus defences against SQL injection. It is topic 14 of the Databases area, which carries 10% of the NSCT according to HEC's Areas of Competencies. In 2026 candidates averaged 42.3% in Databases, per the HEC NSCT report and APP.
The topic overlaps with the separate Cyber Security area, which carries 5% and had 47.2% accuracy in the same sources. Its web application security topic covers injection from the attacker's side. This page follows Silberschatz and Elmasri-Navathe.
Authorisation
Authentication checks who you are. Authorisation decides what you may do once you are in. There are three main models:
| Model | Who decides | Mechanism |
|---|---|---|
| Discretionary (DAC) | The object's owner | GRANT and REVOKE privileges |
| Mandatory (MAC) | The system | Security classes on data, clearances on users |
| Role-based (RBAC) | Administrators | Privileges granted to roles, roles granted to users |
The usual MAC model is Bell-LaPadula, with classes ordered Top Secret > Secret > Confidential > Unclassified. Its simple security property is "no read up": a subject may read an object only if its clearance is at least the object's class. Its *-property is "no write down", which stops a Secret user, or a Trojan horse running as that user, from copying Secret data into an Unclassified table.
Other controls are views, which give a clerk only the columns they need, audit trails and encryption at rest and in transit. Exam angle: DAC controls access to an object but not where data flows after it is read. That flow is the gap MAC closes.
GRANT/REVOKE
GRANT SELECT, INSERT ON marks TO teacher; -- teacher is a role
GRANT teacher TO ali;
GRANT UPDATE (salary) ON emp TO hr_clerk; -- column-level privilege
GRANT SELECT ON emp TO A WITH GRANT OPTION; -- A may pass it on
REVOKE SELECT ON emp FROM A CASCADE;
The privileges are SELECT, INSERT, UPDATE, DELETE, REFERENCES (needed to declare a foreign key, because a foreign key can block the owner's deletes) and USAGE. PUBLIC means every user, including users created later.
Revocation follows the authorisation graph, with the DBA at the root and an edge for each grant. After a revoke, a user keeps a privilege only if some path from the root still supports it:
| Grants (all WITH GRANT OPTION) | Revoke | Result |
|---|---|---|
| DBA → A, A → B | DBA revokes A, CASCADE | A and B lose it |
| DBA → A, DBA → B, A → C, B → C | DBA revokes A, CASCADE | B and C keep it (through B) |
| DBA → A, A → B, B → C, C → B | DBA revokes A, CASCADE | B and C lose it (their cycle no longer reaches the DBA) |
RESTRICT makes the REVOKE fail if it would cascade. REVOKE GRANT OPTION FOR removes only the right to pass the privilege on. The SQL standard requires you to write CASCADE or RESTRICT. Silberschatz notes that most systems cascade by default when you leave it out, so check your DBMS. Exam angle: cycles do not keep a privilege alive. Only a path from the DBA does.
SQL injection
SQL injection happens when untrusted input is pasted into SQL text and changes the query's structure. We ran this login check in Python's sqlite3:
sql = "SELECT * FROM users WHERE name = '" + u + "' AND pass = '" + p + "'"
| Input | Query becomes | Effect |
|---|---|---|
p = ' OR '1'='1 |
... name = 'ali' AND pass = '' OR '1'='1' |
Every row returned, because AND binds tighter than OR |
u = admin'-- |
... name = 'admin'--' AND pass = ... |
Logs in as admin, because the password test is commented out |
search = ' UNION SELECT name, pass FROM users-- |
Extra rows from users | Dumps passwords. The column count must match the original SELECT |
id = 0 OR 1=1 (numeric field) |
... WHERE id = 0 OR 1=1 |
Every row returned, with no quote needed |
Other forms include blind injection, where a true/false reply leaks data one bit at a time, and second-order injection, where stored data is concatenated into a later query. The fix is parameterised queries: con.execute("SELECT * FROM users WHERE name = ?", (u,)) returned 0 rows for the same attack input. Add least privilege, so the app account cannot DROP tables, and validate input. Python's execute() also refuses stacked queries such as '; DROP TABLE users; -- with a ProgrammingError, but that is a library rule, not a defence you should rely on.
Exam angle: escaping quotes does not protect numeric positions, and a stored procedure that concatenates strings into dynamic SQL is still injectable.
Common traps
- Thinking REVOKE ... CASCADE removes a user's privilege even when another grant path from the DBA still exists.
- Mixing up the two Bell-LaPadula rules: simple security is no read up, and the *-property is no write down.
- Believing a stored procedure or input escaping alone stops injection.
- Assuming
' OR '1'='1in the password field returns only one user. Because of operator precedence it returns every row. - Treating encryption at rest as an injection defence. Queries through the DBMS see decrypted data.
Worked examples
Understanding. What does WITH GRANT OPTION give the grantee? Answer: the right to grant that same privilege to other users. It gives no extra privileges and no ownership.
Application. The DBA grants SELECT to P and Q, both WITH GRANT OPTION. P grants it to R, then the DBA revokes Q's privilege with CASCADE. Who holds SELECT? Answer: P and R. Q's privilege is gone, but R's comes through P, and P's path to the DBA is intact.
Analysis. A report page builds "... ORDER BY " + col from a URL parameter, and the developer says "we use prepared statements everywhere". Is it safe?
Answer: no. Placeholders can bind values, but not identifiers such as column names, so this part of the query is still built by concatenation. Check col against an allow-list of real column names.
Practise
The quiz below has 100 Database Security questions, which you can filter by tier and difficulty.
Practise: 100 questions
FAQs
Is database security part of the NSCT Cyber Security area?
Both. HEC lists Database Security as a topic in the Databases area (10%), while the Cyber Security area (5%) covers attacks such as injection more broadly. Study GRANT/REVOKE and the access-control models here, then use Cyber Security MCQs for the attacker's view and the OWASP risks.
What is the difference between DAC, MAC and RBAC?
In DAC, the owner of each object grants and revokes privileges as they choose. In MAC, the system enforces labels and clearances that owners cannot override, for example under Bell-LaPadula. RBAC groups privileges into roles that match job functions, then assigns roles to users. SQL supports DAC and RBAC directly. MAC needs special DBMS features.
Why are prepared statements safer than escaping input?
A prepared statement is parsed with placeholders before any data arrives, so the bound values can only ever be data. Escaping depends on handling every context correctly, including quotes, numeric positions and character encodings, and a single missed case reopens the hole. Use parameters for values and allow-lists for identifiers.
Next step
Continue with Distributed Databases MCQs, go back to the Databases hub, or try a timed NSCT mock test.