SQL Data Control Language (DCL) – GRANT and REVOKE Tutorial

SQL Data Control Language (DCL) – GRANT and REVOKE

Data Control Language (DCL) in SQL is used to control access to data in a database. The two main DCL commands are GRANT and REVOKE, which manage user privileges.


1. GRANT

Definition: Grants specific privileges (permissions) to a user or role on database objects such as tables, views, or procedures.

Syntax:

GRANT privilege_type
ON object_name
TO user_name;

Example:

GRANT SELECT, INSERT
ON Student
TO user1;

User user1 can now SELECT and INSERT data into the Student table.


2. REVOKE

Definition: Removes previously granted privileges from a user or role.

Syntax:

REVOKE privilege_type
ON object_name
FROM user_name;

Example:

REVOKE INSERT
ON Student
FROM user1;

This removes the INSERT privilege from user1 on the Student table.


Lab Practice Tasks

  1. Grant SELECT privilege on the Employee table to a user.
  2. Grant multiple privileges (SELECT, UPDATE) on Department table to another user.
  3. Revoke a privilege and verify access by attempting an unauthorized operation.

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন