SQL Interview Questions · Question 12

A new intern should only be able to view the Employees table but should not modify it. Which SQL command will you use?

Interview preparation resource from Gate Smashers.

Interview-ready answer

Grant only SELECT permission on the Employees table to the intern's database user (or, preferably, to a read-only role assigned to that user). Example SQL: GRANT SELECT ON Employees TO intern_user;

SQL querysql
GRANT SELECT ON Employees TO intern_user;
Understand it clearly

Direct answer

Grant only the SELECT permission on the Employees table to the intern's database user or to a read-only role assigned to that user. This allows the intern to view rows but not insert, update, or delete them.

Rationale

Use GRANT SELECT to follow the principle of least privilege: permit read access without granting INSERT, UPDATE or DELETE.

  • Least privilege: GRANT SELECT permits reads without granting INSERT, UPDATE or DELETE.
  • Role recommendation: Production systems commonly grant permissions to roles for easier auditing and management; assign the intern a read-only role if possible.

Syntax and notes

Syntax and schema qualification vary by database. Use the GRANT statement appropriate for your RDBMS and include schema qualification if required.