Download Triggers Seminar

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Serializability wikipedia , lookup

DBase wikipedia , lookup

Relational algebra wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Oracle Database wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Microsoft Access wikipedia , lookup

Concurrency control wikipedia , lookup

Database wikipedia , lookup

Functional Database Model wikipedia , lookup

Btrieve wikipedia , lookup

Ingres (database) wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Null (SQL) wikipedia , lookup

Clusterpoint wikipedia , lookup

Database model wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Relational model wikipedia , lookup

SQL wikipedia , lookup

PL/SQL wikipedia , lookup

Transcript
Writing Triggers
1. Scenario
Typical component of any sales system used in supermarket chains is a database schema for registering customer
sales. Suppose the following two relations are used to represent the sales operations and the items sold in each of
them:
sales(invNo:INTEGER, cassier:STRING, positions:INTEGER, total:MONEY, sale_date:DATE)
items(posNo:INTEGER, invno:INTEGER, name:STRING, price:MONEY, qty:INTEGER, sum:MONEY)
Assuming most of the calculations done during customer sales are implemented using database triggers, in this
seminar you should write and experiment with various triggers for automation of certain typical operations for sales.
2. Aims of this seminar


To practice writing of row and statement triggers against database tables using standard SQL and to explore the
effect of their execution using interactive database manipulation
To analyze the reasons for table mutation when using database triggers and the restrictions for avoiding them
3. Tasks
a)
Write SQL DDL statements for creating database tables which implement the above database schema and
execute them using SQL*Plus under your database account (Solution: given in sales-database.sql file)
b) Write row trigger against ITEMS table, which calculates automatically the sum of all bought items using the
unit price and the quantity for each of them, and another statement trigger against the above tables which
automatically updates the total sum and the number of different positions bought during the current sale
operation; execute them against the same account (Solution: given in sales-row-triggers.sql file)
c)
Prepare and load some test data for two different sales operations with several item positions and explore the
result of automatic trigger execution after each of them (Solution: given in sales-operations.sql file)
d) Create an audit table HIST for registering different possible sales operations performed typically by the
cashiers at the till according to the following specification:
hist(no:INTEGER,tab_name:STRING,sql_op:CHAR,dat:DATE,col_name:STRING,count:INTEGER)
where sql_op can have one of the two possible values - ’U’ for updating of prices and quantities and ’D’ –
for deleting of some of the positions in the current sales operation or canceling the entire operation (Solution:
given in sales-audit.sql file)
e)
Write some statement triggers against the two tables SALES and ITEMS which register in HIST table the
corresponding operations performed at the till and execute them under the same account (Solution: given in
sales-statement-triggers.sql file)
f)
Change item prices, quantities, positions and sales summaries in the existing sales operations (Solution: given in
sales-changes.sql file). Analyze and explain the generated messages.
g) Execute the file sales-mutating-tables.sql under the same account and explore its content (Hint: it
contains row triggers which could cause table mutation when executed)
h) Run some operations for changing prices, quantities, positions and sales summaries and analyze the generated
messages (Hint: You may wish to prepare your own file similar to sales-changes.sql)