-- Dec 10 Practice Final Solutions
3. Give SQL to do the following DML operations:
(a) Create a table R(A:int,B:int,C:int) where A, B is the primary key, C is a key, the default value for B is 10, and B must be at least 5
CREATE TABLE R (
A INT,
B INT DEFAULT 10 CHECK (B >= 5),
C INT UNIQUE,
PRIMARY KEY (A, B)
);
(b) Insert into R all distinct values (A, B, C) from S(A:int, B:int, C:int, D:int) where D > 10
INSERT INTO R
(SELECT DISTINCT A, B, C
FROM S
WHERE S.D > 10);
4. Give SQL for the following operations on relation R(A:int,B:int,C:int):
(a) Delete all rows of R where A>5 and B<10
DELETE FROM R
WHERE A > 5 AND B < 10;
(b) Update the salaries of all MovieExecs with a salary less than 10,000,000 to make it 10,000,000
UPDATE MovieExecs
SET salary = 10000000
WHERE salary < 10000000;
Student names: Priscilla Ng, Monsi Magal, Serena Pascual, D. Adam Ball, Kevin Prakasa
(
Edited: 2018-12-10)
3. Give SQL to do the following DML operations:
(a) Create a table R(A:int,B:int,C:int) where A, B is the primary key, C is a key, the default value for B is 10, and B must be at least 5
CREATE TABLE R (
A INT,
B INT DEFAULT 10 CHECK (B >= 5),
C INT UNIQUE,
PRIMARY KEY (A, B)
);
(b) Insert into R all distinct values (A, B, C) from S(A:int, B:int, C:int, D:int) where D > 10
INSERT INTO R
(SELECT DISTINCT A, B, C
FROM S
WHERE S.D > 10);
4. Give SQL for the following operations on relation R(A:int,B:int,C:int):
(a) Delete all rows of R where A>5 and B<10
DELETE FROM R
WHERE A > 5 AND B < 10;
(b) Update the salaries of all MovieExecs with a salary less than 10,000,000 to make it 10,000,000
UPDATE MovieExecs
SET salary = 10000000
WHERE salary < 10000000;
Student names: Priscilla Ng, Monsi Magal, Serena Pascual, D. Adam Ball, Kevin Prakasa