Practice For SQL and Constraints : Product-PC-Laptop-Printer
Practice For SQL and Constraints : Product-PC-Laptop-Printer
(SELECT maker
FROM Laptop NATURAL JOIN Product)
MINUS
(SELECT maker
FROM PC NATURAL JOIN Product);
Product(maker, model, type) b) Find those hard-disk sizes
PC(model, speed, ram, hd, rd, price) that occur in two or more
PC's.
Laptop(model, speed, ram, hd, screen, price)
Printer(model, color, type, price)
SELECT hd
FROM PC
GROUP BY hd
HAVING COUNT(model) >= 2;
Product(maker, model, type) c) Find those manufacturers
PC(model, speed, ram, hd, rd, price) of at least two different
computers (PC or Laptops)
Laptop(model, speed, ram, hd, screen, price) with speed of at least 700.
Printer(model, color, type, price)
SELECT Product.maker
FROM PC, Product
WHERE PC.model=Product.model
GROUP BY Product.maker
HAVING COUNT(PC.model)=3;
Or:
SELECT maker
FROM PC NATURAL JOIN Product
GROUP BY maker
HAVING COUNT(model)=3;
Product(maker, model, type) e) Using two INSERT
PC(model, speed, ram, hd, rd, price) statements, store in the
database the fact that PC
Laptop(model, speed, ram, hd, screen, price) model 1100 is made by
Printer(model, color, type, price) manufacturer C, has speed
1800, RAM 256, hard disk
80, a 20x DVD, and sells
INSERT INTO Product(maker,model,type)
for $2499.
VALUES('C',1100,'PC');
DELETE FROM PC
WHERE hd<20;
Product(maker, model, type) h) Delete all laptops made by
PC(model, speed, ram, hd, rd, price) a manufacturer that doesn’t
make printers.
Laptop(model, speed, ram, hd, screen, price)
Printer(model, color, type, price)
UPDATE Product
SET maker='B'
WHERE maker='C';
Product(maker, model, type) j) For each PC, double the
PC(model, speed, ram, hd, rd, price) amount of RAM and add 20
GB to the amount of hard
Laptop(model, speed, ram, hd, screen, price) disk.
Printer(model, color, type, price)
UPDATE PC
SET ram=ram*2, hd=hd+20;
Product(maker, model, type) k) For each laptop made by
PC(model, speed, ram, hd, rd, price) manufacturer B, add one
inch to the screen size and
Laptop(model, speed, ram, hd, screen, price) subtract $100 from the
Printer(model, color, type, price) price.
UPDATE Laptop
SET screen=screen+1, price=price-100
WHERE model IN
(SELECT model
FROM Product
WHERE maker='B'
);
Constraints – PCs, Laptops, Printers
Product(maker, model, type)
PC(model, speed, ram, hd, rd, price)
Laptop(model, speed, ram, hd, screen, price)
Printer(model, color, type, price)