Professional Documents
Culture Documents
Tutorial 4
Tutorial 4
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.
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.