In: Computer Science
**I request you to Please Provide the positive Rating**
Answer each of the following questions
Emp(eid: integer, ename: string, age: integer, salary: real)
Works(eid: integer, did: integer, pcttime: integer)
Dept(did: integer, dname: string, budget: real, managerid: integer)
(a) (5 points) Give an example of a foreign key constraint that involves the Dept relation. What are the options for enforcing this constraint when a user attempts to delete a Dept tuple?
ANSWER) DID IS THE FOREIGN KEY IN THE WORKS TABLE.
CREATE TABLE WORKS(eid integer, did integer, pcttime integer, FOREIGN KEY eid REFERENCES Emp(eid ), FOREIGN KEY DID REFERENCES DEPT(DID))
CREATE TABLE DEPT(did integer, dname VARCHAR(200), budget real, managerid integer, PRIMARY KEY(DID))
(b) (5 points) Write the SQL statements required to create the preceding relations, including appropriate versions of all primary and foreign key integrity constraints.
ANSWER) CREATE TABLE Emp(eid integer, ename VARCHAR(200), age integer, salary real,PRIMARY KEY (EID))
CREATE TABLE WORKS(eid integer, did integer, pcttime integer, FOREIGN KEY eid REFERENCES Emp(eid ), FOREIGN KEY DID REFERENCES DEPT(DID))
CREATE TABLE DEPT(did integer, dname VARCHAR(200), budget real, managerid integer, PRIMARY KEY(DID))
(c) (5 points) Define the Dept relation in SQL so that every department is guaranteed to have a manager.
CREATE TABLE DEPT(did integer, dname VARCHAR(200), budget real, managerid integer NOT NULL, PRIMARY KEY(DID))
d) (5 points) Write an SQL statement to add John Doe as an employee with eid = 101, age = 32 and salary = 15, 000.
INSERT INT EMP(101,"John Doe",32,15000);
(e) (5 points) Write an SQL statement to give every employee a 10 percent raise.
UPDATE EMP SET SALARY=SALARY+(0.1*SALARY) ;
(f) (5 points) Write an SQL statement to delete the Toy department. Given the referential integrity constraints you chose for this schema, explain what happens when this statement is executed.
DELETE FROM DEPT WHERE DNAME="TOY";
when this statement is executed, it will delete all the roes which have the department name as 'toy'