ITP

BE - Database Management Systems

Explain GRANT, REVOKE and SAVEPOINT commands with suitable example.

In : BE Subject : Database Management Systems

1. GRANT Command

The GRANT command is used to give specific privileges to a user or a role. Privileges may include SELECT, INSERT, UPDATE, DELETE, or even permission to grant privileges to others.

Syntax:

GRANT privilege_list ON object_name TO user_name;

Example:

GRANT SELECT, INSERT ON Students TO User1;

This allows User1 to read (SELECT) and insert records into the Students table.

2. REVOKE Command

The REVOKE command is used to withdraw previously granted privileges from a user or role.

Syntax:

REVOKE privilege_list ON object_name FROM user_name;

Example:

REVOKE INSERT ON Students FROM User1;

This removes the INSERT privilege from User1 on the Students table, but any other granted privileges (like SELECT) remain.

3. SAVEPOINT Command

The SAVEPOINT command is used in transaction management. It allows you to set a checkpoint within a transaction so that you can roll back part of the transaction instead of rolling back the entire transaction.

Syntax:

SAVEPOINT savepoint_name;
ROLLBACK TO savepoint_name;

Example:

BEGIN;
INSERT INTO Students VALUES (101, 'John');
SAVEPOINT sp1;
INSERT INTO Students VALUES (102, 'Alice');
ROLLBACK TO sp1;
COMMIT;

 

About us

A truly open platform where you may ask questions and get answers. We also provide comprehensive and easy-to-understand answers to question papers.  discover...

Site status

Flag Counter

Privacy Policy

Sitemap