










































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An in-depth exploration of various sql functions and triggers, including user-defined functions, conditional updates, data trigger events, statement vs. Row triggers, data trigger examples, canceling data changes in triggers, cascading triggers, trigger loops, transactions, sql transaction code, concurrent access, sql pessimistic lock, optimistic locks, acid transactions, phantom rows, generated keys, methods to generate keys, database cursor program structure, cursor positioning with fetch, problems with multiple users, changing data with cursors, dynamic parameterized cursor queries, and quantity changed events.
Typology: Slides
1 / 50
This page cannot be seen from the preview
Don't miss anything!
1
2
4
Function to Perform Conditional
Update
5
7
INSERT
DELETE
UPDATE
BEFORE AFTER
8
Before Update On table
After Update On table
Before Update Row 442
After Update Row 442
Update Row 442
… other rows
10
11
Sale(SaleID, SaleDate, …)
OrderItem(OrderID, ItemID, Quantity, …)
Order(OrderID, OrderDate, …)
Inventory(ItemID, QOH, …)
SaleItem(SaleID, ItemID, Quantity, …)
AFTER INSERT UPDATE Inventory SET QOH = QOH – newrow.Quantity
WHEN newrow.QOH < newrow.Reorder INSERT {new order} INSERT {new OrderItem}
changes.
13
Savings Accounts
Inez: 5340.
Checking Accounts
Inez: 1424.
Transaction
Steps Savings Balance Checking Balance
Problem arises if transaction is not completed
14
16
CREATE FUNCTION TransferMoney(Amount Currency, AccountFrom Number, AccountTo Number) RETURNS NUMBER curBalance Currency; BEGIN DECLARE HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; Return -2; -- flag for completion error END; START TRANSACTION; -- optional SELECT CurrentBalance INTO curBalance FROM Accounts WHERE (AccountID = AccountFrom); IF (curBalance < Amount) THEN RETURN -1; -- flag for insufficient funds END IF UPDATE Accounts SET CurrentBalance = CurrentBalance – Amount WHERE AccountID = AccountFrom; UPDATE Accounts SET CurrentBalance = CurrentBalance + Amount WHERE AccountID = AccountTo; COMMIT; RETURN 0; -- flag for success END; Docsity.com
17
SAVEPOINT StartOptional; UPDATE … UPDATE … If error THEN ROLLBACK TO SAVEPOINT StartOptional; END IF COMMIT;
time
start Required elements
StartOptional Risky steps
commit
Partial rollback
Receive Payment Balance Place New Order
19
20
ID Balance Jones $ $
Read balance 800
Subtract pmt -
Save new bal. 600
Read balance Receive error message that it is locked.