Chapter 3_Performing SQL Operation
Chapter 3_Performing SQL Operation
As a first step, the application will check the balance of the account,
and then it will deduct the money from the source account.
Along with these two processes, it will keep the log of this money withdrawing
activity.
Advance Database using PL/SQL
Unit 3 : Performing SQL Operations from PL/SQL
The transaction properties are referred to as ACID (Atomicity, Consistency, Isolation, Durability) property
Advance Database using PL/SQL
Unit 3 : Performing SQL Operations from PL/SQL
ROLLBACK: It is a command used to cancel all modifications and goes into their
previous state.
Advance Database using PL/SQL
Unit 3 : Performing SQL Operations from PL/SQL
COMMIT
COMMIT in SQL is a transaction control language that is used to
permanently save the changes done in the transaction in
tables/databases. The database cannot regain its previous state after
its execution of commit.
The COMMIT TRANSACTION statement applies the data changes to the database and
the changed data will become permanent.
Syntax:
COMMIT;
Advance Database using PL/SQL
Unit 3 : Performing SQL Operations from PL/SQL
BEGIN tran t;
ROLLBACK Command
If any error occurs with any of the SQL grouped statements, all changes need to be aborted. The
process of reversing changes is called rollback.
Example Query
ROLLBACK Command
begin tran t
if(@SalesPrice<16000)
begin
print'An SalesPrice less than 16000 is not valid; query is rolled back';
rollback tran t;
end
else
begin
print 'data is inserted'
end
Advance Database using PL/SQL
Unit 3 : Performing SQL Operations from PL/SQL
COMMIT TRANSACTION
In this output, we can see that the insert statement was executed successfully. However, executing the update
statement found an error due to the data type conversion issue. In this case, the SQL Server does not allow
any changes in the database, which means the insert operation does not add any value, and the select
statement is not executed.
Advance Database using PL/SQL
Unit 3 : Performing SQL Operations from PL/SQL
CURSORS
Cursor is a Temporary Memory or Temporary Work Station. It is Allocated
by Database Server at the Time of Performing DML(Data Manipulation Language)
operations on the Table by the User. Cursors are used to store Database Tables.
“Lock is defined as a mechanism to ensure data integrity, consistency while allowing concurrent
access to data. It is used to implement concurrency control when multiple users access Database to
manipulate its data at the same time”
Different Models of SQL Server locks
•Shared(S)
• Used for select operations
• Enable other sessions to perform select operations but prevent updates
• read-only operations
• Operation with SELECT statement generally use in Shared mode.
•Exclusive(X)
• Used for DML operations
• Prevents other users from accessing the resource.
• Operations, such as INSERT, UPDATE, or DELETE means DML query. Ensures that multiple updates cannot
be made to the same resource at the same time.
Advance Database using PL/SQL
Unit 3 : Performing SQL Operations from PL/SQL
•Update(U)
• Preliminary stage for exclusive lock. Used by the server when filtering the records to be modified
• Prevents other update locks
• A solution to the cycle deadlock problem
•Intent
• Intent Locks are used for establishing a lock Hierarchy.
• The types of intent locks are:
• intent shared (IS),
• intent exclusive (IX)
• shared with intent exclusive (SIX).
•Schema
• Schema locks are used when an operation dependent on the schema of a table is executing.
• The types of schema locks are:
• Schema modification (Sch-M) and
• Schema stability (Sch-S).