Database Security MCQs for NSCT

By the NSCT Exam Editorial Team · Updated 2026-11-24 · Facts checked against official sources on 2026-11-24

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

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

Interactive quiz loading. The first 10 questions are shown below.

  1. Which statement lets the user ali read the rows of table marks?

    1. GRANT READ ON marks TO ali;
    2. ALLOW SELECT ON marks FOR ali;
    3. GRANT SELECT ON marks TO ali;
    4. GRANT ali SELECT ON marks;
    Show answer

    Answer: C. GRANT SELECT ON marks TO ali;

    The SQL form is GRANT <privilege list> ON <object> TO <user or role>. Reading rows needs the SELECT privilege. SQL has no READ table privilege and no ALLOW statement, and the grantee comes after TO.

  2. What does WITH GRANT OPTION add to GRANT SELECT ON marks TO ali?

    1. Ali becomes the owner of the marks table
    2. Ali may also update and delete rows in marks
    3. Ali's privilege can no longer be revoked
    4. Ali may pass the SELECT privilege on marks to other users
    Show answer

    Answer: D. Ali may pass the SELECT privilege on marks to other users

    WITH GRANT OPTION lets the grantee grant the same privilege onward. It does not transfer ownership, add other privileges such as UPDATE, or protect the privilege from REVOKE.

  3. Discretionary access control (DAC) in SQL databases is mainly implemented with which mechanism?

    1. Security labels on every row and clearances on every user, set by the system
    2. Privileges that owners grant and revoke with GRANT and REVOKE
    3. Encrypting every column with a separate key
    4. Firewalls that block the database port
    Show answer

    Answer: B. Privileges that owners grant and revoke with GRANT and REVOKE

    In DAC, the owner of an object decides, at their discretion, who gets which privileges, using GRANT and REVOKE. Labels and clearances enforced by the system describe mandatory access control. Encryption and firewalls are other security layers, not access control models.

  4. Which statement best describes mandatory access control (MAC)?

    1. The system enforces access using security classes on data and clearances on users, and owners cannot override it
    2. Each object's owner decides who may access it
    3. Users get privileges through job roles such as 'clerk' or 'manager'
    4. Every user may read everything but write only their own rows
    Show answer

    Answer: A. The system enforces access using security classes on data and clearances on users, and owners cannot override it

    MAC assigns security classes (such as Top Secret, Secret, Confidential, Unclassified) to objects and clearances to subjects, and the system enforces rules such as Bell-LaPadula. Owner discretion is DAC, and job-based privileges describe RBAC.

  5. What is SQL injection?

    1. Inserting a large number of rows to slow a database down
    2. Adding a new index to speed up a query
    3. An attack where user input is interpreted as part of the SQL statement, changing what it does
    4. Copying a database to another server without permission
    Show answer

    Answer: C. An attack where user input is interpreted as part of the SQL statement, changing what it does

    SQL injection happens when an application builds SQL by joining strings with untrusted input. Specially crafted input closes a string or adds operators so the database runs a different query, for example one that skips a password check.

  6. Which is the most effective primary defence against SQL injection?

    1. Hiding database error messages from users
    2. Renaming tables so attackers cannot guess them
    3. Using HTTPS between the browser and the web server
    4. Parameterised queries (prepared statements) that send data separately from the SQL text
    Show answer

    Answer: D. Parameterised queries (prepared statements) that send data separately from the SQL text

    With parameterised queries the SQL structure is fixed first and the input is bound as a value, so it can never become SQL code. Hiding errors and renaming tables only slow attackers down, and HTTPS protects data in transit but not the query itself.

  7. In SQL, what is a role?

    1. A named collection of privileges that can be granted to users or other roles
    2. A user account with no password
    3. A view that hides certain columns
    4. A log of the statements a user has run
    Show answer

    Answer: A. A named collection of privileges that can be granted to users or other roles

    CREATE ROLE teacher creates a named set of privileges. Granting privileges to the role and the role to users makes administration easier: when staff change jobs you change their roles, not dozens of individual grants. This is role-based access control (RBAC).

  8. What is the difference between authentication and authorisation in a DBMS?

    1. Authentication decides what the user may do; authorisation checks who the user is
    2. They are two names for the same password check
    3. Authentication applies to tables; authorisation applies only to views
    4. Authentication checks who the user is; authorisation decides what that user may do
    Show answer

    Answer: D. Authentication checks who the user is; authorisation decides what that user may do

    Authentication verifies identity, for example with a password or certificate. Authorisation then checks the privileges of that identity, for example whether it holds SELECT on a table. A user can be authenticated yet still not authorised for an action.

  9. What does GRANT SELECT ON notices TO PUBLIC do?

    1. Gives every current and future user the SELECT privilege on notices
    2. Makes the notices table visible on the internet
    3. Gives only the DBA the SELECT privilege
    4. Makes notices read-only for its owner
    Show answer

    Answer: A. Gives every current and future user the SELECT privilege on notices

    PUBLIC stands for all users of the database, including users created later. It does not publish data outside the database. Use it with care, because REVOKE from PUBLIC does not remove privileges granted to users individually.

  10. What is a database audit trail?

    1. A backup copy of the database taken every night
    2. The list of indexes on each table
    3. A diagram of the database schema
    4. A log recording which user performed which operations on which data, and when
    Show answer

    Answer: D. A log recording which user performed which operations on which data, and when

    An audit trail records security-relevant actions, such as logins, privilege changes and updates to sensitive tables, with the user and time. It helps detect misuse and trace who made a change. Backups support recovery, not accountability.

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.