Data Control language: Grant, Revoke

Data Control Language (DCL) acts as the database security guard, using GRANT and REVOKE to control exactly which users can see or modify specific tables.

10 min read · 12 cards · 3 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

The Open-Door Database Nightmare

In your Semester 1 labs, when you wrote programs or managed small text files, you were the sole owner of your system. But in real-world software applications, like a university management portal or a banking application, hundreds of different users log in daily. If a junior receptionist needs to check a student's address, should they also have the power to alter exam marks or delete the entire fee ledger? Giving everyone the root administrative password is a recipe for absolute disaster. How do we open our database to multiple users while ensuring they can only perform actions explicitly required by their job roles?

Theory

The College Master Key vs. The Specific Library Pass

Imagine your college campus building. The Principal holds the master key that can open the staff room, the examination locker, the server room, and the main gate. Giving a first-semester student this master key just so they can sit in a specific classroom is highly dangerous. Instead, the college issues a Library Card (a specific pass) that permits you to enter the library reading room and borrow books, but completely blocks you from stepping into the examination office. In SQL, Data Control Language (DCL) works exactly like issuing or taking back these specific access passes without changing the physical locks on the doors.

Theory

Privilege Security Architecture Formally

The Data Control Language (DCL) component of SQL consists of commands that control access permissions and authorization levels within a database system. Permissions are broadly classified into two categories: System Privileges (granting rights to perform administrative actions across the database instance, like CREATE TABLE or CONNECT) and Object Privileges (granting rights to execute operations like SELECT, INSERT, UPDATE, or DELETE on a specific table or view). The two foundational commands of DCL are GRANT (which bestows privileges) and REVOKE (which withdraws them).

At a glance

Table 1: Essential structural syntax mapping for SQL Data Control Language commands.

DCL Command PropertySyntax Structure FrameworkOperational Security Outcome
GRANT PrivilegesGRANT privilege_name ON object_name TO user_name;Provides specified operations access to a targeted user account instantly.
REVOKE PrivilegesREVOKE privilege_name ON object_name FROM user_name;Immediately strips the defined privileges away, blocking future execution attempts.
WITH GRANT OPTIONAppended to a GRANT statement string.Allows the receiving user to further pass on those identical rights to other colleagues.
PUBLIC AccountTargeting the keyword 'TO PUBLIC' instead of a user name.Broadcasts the defined read or write privileges to every single user account in the system.

Theory

Worked Example: Enforcing Library Ledger Security

Let us trace how a Database Administrator (DBA) manages access control for a newly hired library assistant named rahul_clerk. We will establish a secure table, issue specific row manipulation privileges, and subsequently withdraw them to witness security enforcement in action.

Practical

Library Database Security Pipeline

-- Step 1: Administrator creates the master inventory table
CREATE TABLE library_books (
    book_id INT PRIMARY KEY,
    title VARCHAR(100),
    copies_available INT
);

-- Step 2: Grant specific read and add privileges to the clerk account
GRANT SELECT, INSERT ON library_books TO rahul_clerk;

-- Step 3: Simulate the clerk successfully adding a new textbook record
-- (Executed under rahul_clerk session space)
INSERT INTO library_books VALUES (201, 'Core Python Programming', 5);

-- Step 4: Revoke inserting powers when the internship duration ends
REVOKE INSERT ON library_books FROM rahul_clerk;

Copy and open Oracle FreeSQL
Oracle FreeSQL is a free online editor for Oracle SQL. The code is copied first: paste it there and run it.

Think first

Trace the Unauthorized Operational Block

Suppose that immediately after Step 4 executes, the user account rahul_clerk tries to run two separate statements: first, a 'SELECT * FROM library_books;' query, and second, an 'INSERT INTO library_books VALUES (202, 'Database Systems', 3);' query. What will the RDBMS output for each statement?

Show the answer

The first statement (SELECT) will execute successfully and display the table records, because only the INSERT privilege was revoked, leaving the SELECT permission intact. The second statement (INSERT) will immediately fail and throw an explicit error like 'ORA-01031: insufficient privileges' or 'Permission Denied'. The database system stops the query at the engine level before it can ever touch the underlying storage blocks.

Quiz

Which type of SQL privilege allows a user to perform broad structural database tasks like creating new user accounts, establishing server connections, or creating completely new tables?

  1. Object Privileges
  2. System Privileges
  3. Transaction Privileges
  4. Data Definition Privileges
Show the answer

System Privileges

System privileges grant broad administrative authority across the entire database instance (like CREATE USER or CREATE TABLE). Object privileges, by contrast, are tightly scoped to specific actions on existing individual tables or views (like SELECT or UPDATE on a specific ledger table).

Quiz

If User A grants SELECT privilege on a table to User B 'WITH GRANT OPTION', and later User A revokes that SELECT privilege from User B, what happens to any other users (like User C) who received that privilege directly from User B?

  1. User C retains their access privileges completely unaffected.
  2. The entire database instance crashes with a CascadePrivilegeException error.
  3. User C's privileges are also automatically revoked in a cascading chain effect.
  4. User B retains access, but User C loses it immediately.
Show the answer

User C's privileges are also automatically revoked in a cascading chain effect.

In standard relational database management systems, revoking a privilege from a user who passed it down using WITH GRANT OPTION causes a cascading revocation. Since User B was the root source of User C's authority, once User B loses access, User C's rights are automatically dissolved as well.

Watch out

The Classic Trap: The Missing Table Owner Prefix

A common mark-losing mistake in university examinations is forgetting that when a user like rahul_clerk wants to query a table owned by an administrator or another user, they cannot just write 'SELECT FROM library_books;'. This triggers a 'Table or View does not exist' error! They must prefix the table name with the owner's username schema identifier, like 'SELECT FROM admin.library_books;'. Always specify the schema owner prefix when executing cross-user queries in lab exams!

Theory

Connecting Access Control to Semester 3

Managing granular user privileges forms the bedrock of real-world data security engineering. In Semester 3 Database Administration (BCA301) and cloud infrastructure configurations, you will scale these basic DCL principles into Role-Based Access Control (RBAC), bundling sets of GRANT commands into unified corporate roles (like Manager or Developer) to handle thousands of user clearances securely.

Summary

Key takeaways

  • Data Control Language handles database security containment, user authorization levels, and privileges.
  • The GRANT command issues specific system or object-level operational permissions to user accounts.
  • The REVOKE command safely withdraws previously assigned access privileges from a user session.
  • Privileges are divided into broad administrative System privileges and database object-focused Object privileges.
  • The WITH GRANT OPTION modifier enables users to delegate their received privileges down to sub-users.
  • Memory Hook: GRANT opens the secure gateway, REVOKE shuts the entrance, and always prefix the schema owner!

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Introduction of Relational Model

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Data Control language: Grant, Revoke · Concepts of Relational Database Management Systems · Gri-Learn