Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Advanced Database Systems – IT2210

Tutorial 04– Week 05


Year 2 Semester 2, 2023

1. Create a view in T-SQL( called Cust_Inf containing the following information of customers:
Customer’s number,NIC, name
His/her account information: account number and account type’s name
Using the view above, query Mr.Sampath Wijesinghe’s account information.

2. A policy of the bank is that a single customer cannot have more than 5 accounts. Write a DML
trigger to ensure that this policy is enforeced. Note that the customer can have more than 5
accounts in total from different banks. Test your trigger with sample data.
3. Write a stored procedure, which takes the account number and returns the number of cheques
processed for that account during the current month. Test your stored procedure with sample data.
4. Write a stored procedure that transfers fund between accounts. The input parameters include
account number of source account, account number of destination account and amount to be
transferred. Ensure that the transaction occurs within a single transaction. Also, ensure that
appropriate information is updated in the Transaction table. Test your stored procedure with
sample data.

Objective :Views and Triggers

Create the following database schema only if not exist,

CREATE TABLE Software_Manuals (


item_no varchar(40) PRIMARY KEY,
title varchar(100),
description varchar(100),
version varchar(30),
manufacturer varchar(50) );

CREATE TABLE Copy_SW_Manual (


access_no integer PRIMARY KEY,
item_no varchar(40) REFERENCES Software_Manuals );
CREATE VIEW VW_SW_MANUAL (
title, manufacturer, version, access_no)
AS
SELECT SM.title, SM.manufacturer, SM.version, CSM.access_no
FROM Software_Manuals SM, Copy_SW_Manual CSM
WHERE SM.item_no = CSM.item_no

Create an INSTEAD OF trigger (called “tr_sw_vw_insert”) on the view created above. The trigger should be fired
for an INSERT statement and should do the following:

i. If the inserted row contains an access_no that exists in the table, then update the version, title and
manufacturer columns of Software_Manuals table with the inserted data.
ii. Else, if the title,manufacturer and version exists in the Software_Manuals table, insert a new row to
Copy_SW_Manual table with its items information referencing the existing row of the Software_Manuals
table.
iii. Else, insert rows to Software _Manuals and Copy_SW_Manual tables to reflect the new information.

-------------------------------------- End of Tutorial-------------------------------

You might also like