0% found this document useful (0 votes)
21 views

Experiment 8 Dbms-1

Uploaded by

Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Experiment 8 Dbms-1

Uploaded by

Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

EXPERIMENT NO:-08

Aim: Perform DCL and TCL commands

Theory:

DCL:
DCL (Data Control Language) commands are used to control access to a database. These commands
are used to grant or revoke privileges to users and roles in a database.

• Security:

• Authorization: by giving privileges or view…

• A user can grant access to his database..

• Privileges can insert, update, delete, Alter, select and ALL

• Syntax:

GRANT <privileges> | ALL

ON <table-name> to <USER|PUBLIC>

[with Grant option]

REVOKE : to remove privileges from user.

• Syntax:

REVOKE <privileges> | ALL

ON <table-name> FROM <USER|PUBLIC>


TCL:
TCL stands for Transaction Control Languages. These commands are used for maintaining
consistency of the database and for the management of transactions made by the DML commands.

A Transaction is a set of SQL statements that are executed on the data stored in DBMS.

Whenever any transaction is made these transactions are temporarily happen in database. So to
make the changes permanent, we use TCL commands.
The TCL commands are:
1. COMMIT
2. ROLLBACK
3. SAVEPOINT

1. COMMIT:
This command is used to save the data permanently.

Whenever we perform any of the DML command like -INSERT, DELETE or UPDATE, these can
be rollback if the data is not stored permanently. So in order to be at the safer side COMMIT
command is used.

Syntax: commit;

2. ROLLBACK :

This command is used to get the data or restore the data to the last savepoint or last committed
state. If due to some reasons the data inserted, deleted or updated is not correct, you can rollback
the data to a particular savepoint or if savepoint is not done, then to the last committed state.

Syntax: rollback;

3. SAVEPOINT:

This command is used to save the data at a particular point temporarily, so that whenever needed
can be rollback to that particular point.

Syntax:
Savepoint A;
Application of DCL & TCL Commands:

Examples of DCL commands include GRANT

• GRANT ALL ON emp to public ;

• GRANT ALL ON emp to Scott;

• GRANT SELECT ON dept to XYZ With grant option;

• GRANT INSERT ON dept to XYZ;

• GRANT INSERT(eno) ON emp to Scott;

REVOKE :

Example :

• REVOKE ALL ON emp from public ;

• REVOKE ALL ON emp from Scott;

• REVOKE SELECT ON dept from XYZ With grant option;

• REVOKE INSERT ON dept from XYZ;

• REVOKE INSERT(eno) ON emp from Scott;

TCL:

1. COMMIT:

Example:
Consider the following Table Student:
UPDATE medical_students
SET name = 'Aniket'
WHERE name = 'Alexa';
COMMIT;
ROLLBACK;

By using this command you can update the record and save it permanently by
using COMMIT command.

Now after COMMIT:

If commit was not performed then the changes made by the update command can be rollback.
Now if no COMMIT is performed.

UPDATE medical_students
SET name = 'Sakshi'
WHERE name = 'Nikhil';
After update command the table will be:
Now if ROLLBACK is performed on the above table
rollback;
After Rollback:

If on the above table savepoint is performed:


INSERT INTO medical_students (id, name, marks) VALUES (4, 'Jack', 92);
COMMIT;

UPDATE medical_students
SET name = 'Alexander'
WHERE marks = 79;

SAVEPOINT A;

INSERT INTO medical_students (id, name, marks) VALUES (5, 'Zack', 76);

Savepoint B;

INSERT INTO medical_students (id, name, marks) VALUES (2, 'Zack', 76);

Savepoint C;
SELECT * FROM STUDENT;
So It was all about TCL commands in SQL (transaction control language) with examples.

You might also like