0% found this document useful (0 votes)
92 views23 pages

TCL, DCL & Locks

The document discusses transaction control languages (TCL), data control languages (DCL), and locks in databases. TCL includes commands like commit, rollback, and savepoint that allow grouping of SQL statements into logical transactions and managing changes to databases. DCL controls user privileges and includes grant and revoke commands. There are implicit and explicit locks used for concurrency control - implicit locks are applied automatically while explicit locks are applied by users.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views23 pages

TCL, DCL & Locks

The document discusses transaction control languages (TCL), data control languages (DCL), and locks in databases. TCL includes commands like commit, rollback, and savepoint that allow grouping of SQL statements into logical transactions and managing changes to databases. DCL controls user privileges and includes grant and revoke commands. There are implicit and explicit locks used for concurrency control - implicit locks are applied automatically while explicit locks are applied by users.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

TCL, DCL &

LOCKS

Created by RISHI, SIDDHARTH, AYUSHI, MARGI


 TCL
 TCL stands for Transaction Control Languages.
 A transaction is a set of database operations that performs a particular
task.
 They are used to manage transactions in the database.
 These are used to manage the changes made by DML(Data Manipulation
Language) statement.
 It also allows statements to be grouped together into logical transactions.
 There are three commands in TCL :-
I. Commit.
II. Rollback.
III. Savepoint.
I. Commit :-
 This command is used to save the data permanently. 
 Syntax : Commit;
 A transaction can be committed either :-
i. Explicitly.
ii. Implicitly.
 To commit a transaction explicitly, user needs to request COMMIT
command explicitly.
 A transaction is committed implicitly depending upon executing some
specific commands.
 Commit;
Commit complete.
II. Rollback :-
 Rollback command is used to undo transactions that have not already
been saved to the database.
 This command restores the database to last committed state.
 It is also used with Savepoint command to jump to a Savepoint in a
transaction.
 Syntax : rollback ;
 Oracle also performs auto rollback.
 In situations like, computer failure, oracle automatically rollbacks any
uncommitted work, when the database when the database bought back
next time.
 Rollback ;
Rollback Complete.
III. Savepoint :-
 Savepoint command is used to temporarily save a transaction so that you
can rollback to that point whenever necessary.
  It is used to roll the transaction back to a certain point without rolling
back the entire transaction.
 Savepoint can be created using command SAVEPOINT as given below :
Syntax : SAVEPOINT SAVEPOINT_NAME;  
Savepoint Created.
 A rollback command can also be used to terminate the current transaction
partially.
 Rollback can be used with Savepoint by following syntax :
Syntax : ROLLBACK TO SAVEPOINT SAVEPOINT_NAME;
Rollback Complete.
 DCL
 DCL stands for Data control Language.
 DCL is used to control the privileges given to the users in a Database.
It prevents the other users from making changes or updates to the
database by providing access or removing them to the users.
 It is the responsibility of the database owner or the administrator to
provide privileges to the different users according to their roles or the
business need.
 So the DCL provides the necessary means to maintain the database
effectively so that no other users can make any changes that do not
concern their role or might impact the security of the database.
 Privileges are the permissions provided to the various users for
accessing the different database objects.
 There are two types of privileges and they are Object and System
privileges.
 The System privileges provide permission or access to create tables,
sessions, etc.
 The Object privilege provides access or permission for a query to
execute any operation on the tables in a Database.
 There are two commands in DCL :-
I. Grant
II. Revoke
I. Grant :-
 This command provides the users the access or privileges to the database objects.
 Syntax:
GRANT object privileges
ON object name
TO user name
[WITH GRANT OPTION];
 In the above syntax,
• Privilege denotes the privileges those are granted to the user such as EXECUTE or
ALL etc.
• Object name refers to the name of the database objects such as views, tables, etc.
• User name denotes the name of the users to whom the privileges will be granted,
the PUBLIC is used to grant privileges to all the users.
• WITH GRANT OPTION provides the rights to one user to grant the privileges to the
other users.
II. Revoke :-
 Revoking privileges means to deny permission to user given
previously.
 The owner on an object can revoke privilege granted to another
user.
 A user of the object, who is not an owner, but has been granted
privileges using with GRANT OPTION, can revoke the privilege from
the grantee.
 The REVOKE command is used to revoke privilege.
 Syntax :-
REVOKE object privileges
ON object name
FROM user name;
 LOCKS :-
 A transaction is a set of database operations that performs a
particular task.
 There are two types of transaction :-
1. Single Query Transaction (SQT).
2. Multiple Query Transaction (MQT).
 Single Query Transaction :- Transaction may involve Single SQL
statement, known as Single Query Transaction (SQT).
 Multiple Query Transaction :- Transaction may involve Multiple SQL
statement, known as Multiple Query Transaction (MQT).
 The technique used to protect data when multiple users are
accessing it concurrently is called Concurrency Control.
 Oracle uses a method called ‘LOCKING’ to implement Concurrency
Control.
 Locking means to restrict other users from accessing data
temporarily.
 Lock can be defined as a mechanism used to ensure data integrity
while allowing maximum concurrent access to data.
 In Oracle, Locks are enforced on tables in two ways :-
I. IMPLICIT Locking.
II. EXPLICIT Locking.
1. IMPLICIT Lock :-

 It is automatically acquired by the server to ensure data


Integrity among multiple users.
 This does not require any user intervention.
 Such type of locks are called ‘IMPLICIT Locks’.
 Oracle determines two issues :-
I. Type of Lock.
II. Level of Lock.
I. Type of Lock :-
 Oracle uses two different types of locks depending upon the operation
being performed :
a. Shared Locks
b. Exclusive Locks
a. Shared Locks :-
 They are applicable while performing Read operations.
 Read operations involve only viewing of data, mostly using SELECT
statement.
 Read operations does not modify table data, multiple read operations
can be performed simultaneously without causing any problem in data
integrity.
 This means, multiple users can simultaneously read the same data.
b. Exclusive Lock :-
 They are applicable while performing Write operations.
 Write operations involve only modifying of data, using INSERT,
UPDATE or DELETE statement.
 Write operations modifies table data, multiple write operations can
affect data integrity, and result in inconsistent database.
 This means, multiple users cannot modify the same data
simultaneously.
II. LEVEL OF LOCKS :-
 Multiple users may need to access different parts of the same table.
 If entire table is locked by single user, other users need to wait,
even though they have to access other part the table.
 Oracle provides three different levels to place an implicit locks.
 These levels are determined depending upon the WHERE clause
used in SQL statements.
 Three levels are :-
a. Row level lock.
b. Page level lock.
c. Table level lock.
a. Row Level Lock:-
 This lock is used when a condition given in WHERE clause evaluates
to single row.
 For Example:- … WHERE ano = ‘A01’;
 In this case, only single row is locked.
 Other records of the table can be accessed by other users.
b. Page Level Lock:-
 This lock is used when a condition given in WHERE clause evaluates
to set of row.
 For Example:- … WHERE bname = ‘vvn’;
 In this case, only a particular set of rows are locked.
 Other records of the table can be accessed by other users.
c. Table level lock:-
 This lock is used when a SQl statement does not contain WHERE
clause.
 In this case, a query access entire table, and so entire table is
locked.
 Due to this reason, no any other user can access other part of the
table.
 To solve such kind of problem, an explicit locking can be used.
2. EXPLICIT Locking :-
 In oracle, user can lock data in a table on its own instead of automatic
locking provided by oracle.
 such types of locks are called 'Explicit Locks’.
 An owner of a table can place an explicit lock on that table.
 Some other user can also place an explicit lock if it has privileges for
operations like SELECT, INSERT, UPDATE, and DELETE.
 An explicit lock always overrides the implicit locks placed by oracle on
its own.
 An entire table or records of table can be Explicitly locked by using
one of these two commands:
1. SELECT...FOR UPDATE, and
2. 2. LOCK TABLE.
1. Select … For Update,
 Syntax:
SELECT * FROM tableName FOR UPDATE [ NOW AIT ];
 This statement is used to acquire exclusive locks for performing updates
on records.
 Based on the WHERE clause used with SELECT statement, level of lock
will be applied.
 If table is already locked by other user, then this command will simple
wait until that lock is released.
 If NOWAIT is specified, and table is not free, this command will return
with error message indicating "resource is busy".
 Lock will be released on executing COMMIT or ROLLBACK.
 Other clauses such as DISTINCT,ORDER BY,GROUP BY set operations
cannot be used here with SELECT statement.
2. Lock Table Statement :-
 Syntax:
LOCK TABLE tableNAME
IN lockMode MODE [ NOW AIT ];
 This statement is used to acquire lock in one of several specified
modes on a given table.
 If NOWAIT is specified, and table is not free, this command will
return with error message indicating "resource is busy".
 Various modes of lock are described below:
MODE SPECIFIES…

EXCLUSIVE Allows query on a table, but prohibits any other operation;


Other users can only view data of a table.
SHARED Allows concurrent queries, but no update operation is allowed.

ROW SHARE Specifies row level lock; no user can lock the whole table; allowing concurrent
access for all users of the table.
SHARE UPDATE Same as above; exists for compatibility with older versions.

ROW Similar to ROW SHARE, but prohibit shared locking; so, only one user can
EXCLUSICVE access the table at a time.
THANK YOU SO MUCH FOR YOUR
INTEREST AND ATTENTION

You might also like