0% found this document useful (0 votes)
74 views1 page

Lab SPTG Test

The document describes exercises involving stored procedures and triggers in a database with tables for products, PCs, laptops, and printers. 1. Write stored procedures to: a) Return the PC model with the closest price to a given price b) Return the price of a product given its maker and model c) Insert a new PC record, incrementing the model number if already exists 2. Write triggers to: a) Prevent lowering a PC's price if another has the same speed b) Check a printer's model exists in Products c) Prevent modifications if laptop average price by maker is < $1500 d) Prevent updating a PC's RAM/HD if HD

Uploaded by

duongvdhe182527
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views1 page

Lab SPTG Test

The document describes exercises involving stored procedures and triggers in a database with tables for products, PCs, laptops, and printers. 1. Write stored procedures to: a) Return the PC model with the closest price to a given price b) Return the price of a product given its maker and model c) Insert a new PC record, incrementing the model number if already exists 2. Write triggers to: a) Prevent lowering a PC's price if another has the same speed b) Check a printer's model exists in Products c) Prevent modifications if laptop average price by maker is < $1500 d) Prevent updating a PC's RAM/HD if HD

Uploaded by

duongvdhe182527
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Lab – Stored procedures and Triggers

1. Exercise 9.4.2: Write the following PSM functions or procedures, based on the database
schema
Product(maker, model, type)
PC(model, speed, ram, hd, price)
Laptop(model, speed, ram, hd, screen, price)
Printer(model, color, type, price)
a) Take a price as argument and return the model number of the PC whose price is
closest.
b) Take a maker and model as arguments, and return the price of whatever type of
product that model is.
c) Take model, speed, ram, hard-disk size, and price information as arguments, and insert
this information into the relation PC. However, if there is already a PC with that model
number (tell by assuming that violation of a key constraint on insertion will raise an
exception, then keep adding 1 to the model number until you find a model number that is
not already a PC model number.

2. Exercise 7.5.2: Write the following as triggers. In each case, disallow or


undo the modification if it does not satisfy the stated constraint. The database
schema is from the "PC" example of Exercise 2.4.1:
Product(maker, model, type)
PC(model, speed, ram, hd, price)
Laptop(model, speed, ram, hd, screen, price)
Printer(model, color, type, price)
a) When updating the price of a PC, check that there is no lower priced PC
with the same speed.
b) When inserting a new printer, check that the model number exists in
Product.
c) When making any modification to the Laptop relation, check that the
average price of laptops for each manufacturer is at least $1500.
d) When updating the RAM or hard disk of any PC, check that the updated
PC has at least 100 times as much hard disk as RAM.
e) When inserting a new PC make sure that the model
number did not previously appear in any of PC.

pg. 1

You might also like