(PostGreSQL) AdvancedFeatures (Compatibility Mode)
(PostGreSQL) AdvancedFeatures (Compatibility Mode)
Contents
1. Views
Advanced Features 2. Foreign Keys
3. Transactions
4. Inheritance
NGUYEN Hong Phuong
[email protected]
1 2
3. Transactions An example
A transaction comprises a unit of work Consider a bank database that contains balances
for various customer accounts, as well as total
performed within a DBMS (or similar system)
deposit balances for branches.
against a database, and treated in a coherent
and reliable way independent of other Suppose that we want to record a payment of
transactions. $100.00 from Alices account to Bobs account
UPDATE accounts SET balance = balance - 100.00
It bundles multiple steps into a single, all-or- WHERE name = Alice;
nothing operation UPDATE branches SET balance = balance - 100.00
WHERE name = (SELECT branch_name FROM accounts WHERE
The intermediate states between the steps are name = Alice);
not visible to other concurrent transactions UPDATE accounts SET balance = balance + 100.00
WHERE name = Bob;
If some failure occurs that prevents the
UPDATE branches SET balance = balance + 100.00
transaction from completing, then none of the WHERE name = (SELECT branch_name FROM accounts WHERE
steps affect the database at all. name = Bob);
5 6
1
2/18/2013
9 10
2
2/18/2013
Save points
4. Inheritance
SELECT *
FROM cities
17