Data Control Languages and Transaction
Data Control Languages and Transaction
EXAMPLE
• GRANT INSERT, SELECT on users to Tadiwa;
• Using the grant command, Tadiwa has been granted
permission on the “users” database objects, and he can
insert or query the “users” database.
REVOKE
• This command is used to remove previously granted
access privileges from a user.
• privilege names are
SELECT,UPDATE,DELETE,INSERT,ALTER,ALL
• Syntax
John 79
Jolly 65
Shuzan 70
UPDATE STUDENT
COMMIT;
ROLLBACK;
EXAMPLE
• Now after COMMIT:
Name Marks
John 79
Sherlock 65
Shuzan 70
• After Rollback:
Name Marks
John 79
Jolly 65
Shuzan 70
EXAMPLE
• If save point is performed:
START TRANSACTION;
Commit;
UPDATE NAME
SET NAME = ‘Rossie’
WHERE marks = 70;
Savepoint A;
Savepoint B;
EXAMPLE
Savepoint C
INSERT INTO STUDENT
VALUES ( ‘Bruno’ , 85);
Savepoint C;
SELECT *
FROM STUDENT;
EXAMPLE
• The resulting table will be:
Name Marks
John 79
Jolly 65
Rossie 70
Jack 95
Zack 76
Bruno 85
EXAMPLE
• Now if we rollback to savepoint B:
Rollback to B;
John 79
Jolly 65
Rossie 70
Jack 95
Zack 76
EXAMPLE
• Now if we rollback to savepoint A:
Rollback to A;
John 79
Jolly 65
Rossie 70
Jack 95
Applications of TCL
• Committing Transactions: TCL statements can be used to
commit a transaction, which means to permanently save
the changes made during the transaction to the database.
• Rolling Back Transactions: TCL statements can be used
to roll back a transaction, which means to undo the
changes made during the transaction and restore the
database to its previos state.
• Setting Transaction Isolation Levels: TCL statements can
be used to set the transaction isolation level, which
determines the level of concurrency and consistency in
the database.
Applications of TCL
• Savepoints: TCL statements can be used to set
savepoints within a transaction, allowing for partial
rollback if needed.
• Managing Transactions in Stored Procedures: TCL
statements can be used in stored procedures to manage
transactions within the scope of te procedures.