Question

Answer each of the following questions. The questions are based on the following relational schema: Emp(*eid:...

Answer each of the following questions.

The questions are based on the following relational schema:

Emp(*eid: integer¬, ename: string, age: integer, salary: decimal, doj: date)

Works(*eid: integer, *did: integer, no_of_hours: integer)

Dept(*did: integer, dname: string, budget: real, managerid: integer)

a) Give an example of a foreign key constraint that involves the Dept relation.

b) What are the options for enforcing this constraint when a user attempts to delete a Dept tuple?

c) Define the Dept relation in SQL so that every department is guaranteed to have a manager.

d) Define a view in SQL that holds the employees whose salary is greater than the average salary of their department.

e) Alter the Emp table so that it can hold the city in which the employee resides.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a) In relation Dept, the column managerid is a foreign key constraint which references the primary column *eid of relation Emp. Also, the primary key *did of relation Dept is used as a foreign key in Works relation.

b) If a foreign key constraint is defined on relation Dept, then if an user tries to delete a row from Dept, it will throw an error if there are entries present in the Works table with the to be deleted did value.

In this case, we can define the foreign key constraint with ON DELETE CASCADE.

Cascade deletes from parent to child, so when the parent (referenced) record is deleted, any child (referencing) records are also deleted.

This means that if a tuple is deleted from Dept relation, all the referencing records in relation Works are also deleted.

c) Please find the CREATE TABLE command for Dept relation.

CREATE TABLE Dept (

did INT NOT NULL,

dname VARCHAR(50),

budget REAL,

managerid INT NOT NULL,

PRIMARY KEY(did)

);

d) CREATE VIEW EMP_SALARY AS

SELECT * FROM Emp WHERE salary > avg(salary);

e) ALTER TABLE Emp ADD city VARCHAR(50);

Add a comment
Know the answer?
Add Answer to:
Answer each of the following questions. The questions are based on the following relational schema: Emp(*eid:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following relational schema. An employee can work in more than one department; the pct...

    Consider the following relational schema. An employee can work in more than one department; the pct time field of the Works relation shows the percentage of time that a given employee works in a given department. Emp(eid: integer, ename: string, phone: integer, salary: real) Works(eid: integer, did: integer, pct_time: integer) Dept(did: integer, dname: string, budget: real, managerid: integer) Write the following SQL queries. d) Find the enames of managers who manage the departments with the largest budgets. e) Find the...

  • Consider the following relational schema. An employee can work in more than one department; the p...

    Consider the following relational schema. An employee can work in more than one department; the pct_time field of the Works relation shows the percentage of time that a given employee works in a given department. Emp(eid: integer, ename: string, age: integer, salary: real) Works(eid: integer, did: integer, pct_time: integer) Dept(did: integer, budget: real, managerid: integer) In the above, please note that there is an attribute pcttime (of Integer type) in the Works table, as the schema shows. A tuple/row <1,...

  • Any help appreciated! Question 1 (5 points). Answer each of the following questions briefly. The questions...

    Any help appreciated! Question 1 (5 points). Answer each of the following questions briefly. The questions are based on the following relational schema: Emp( eid: integer, ename: string, age: integer, sala1l1: real) Works( eid: integer, did: integer, pet_time: integer) Dept(did: integer, dname: string, budget: real, managerid: integer) 1. Give an example of a foreign key constraint that involves the Dept relation. 2. Write the SQL statements required to create the preceding relations, including appropriate versions of all primary and foreign...

  • 2. (20 points) Consider the following relational schema. The key attributes are bold and underlined. Employee...

    2. (20 points) Consider the following relational schema. The key attributes are bold and underlined. Employee (eid, ename, sal, hobby) * Work_On (eid, did, date) * Department (did, dname, budget) Consider the following query SELECT E.ename, D.budget FROM Employee E, Work_On W, Deptartment D WHERE E.eid W.eid AND W.did - D.did AND D.dname Computer Science' AND W.date 11-13-2018 a) (10 pts) Draw an initial query tree using Cartesian product, selection, and projection. b) (10 pts) Draw a query tree that...

  • Consider the following relational schemas: Employee (eid: integer, ename: string, Job_title: string, Years_of_experience: integer) Project (pid:...

    Consider the following relational schemas: Employee (eid: integer, ename: string, Job_title: string, Years_of_experience: integer) Project (pid: integer, pname: string, parea: string, mid: integer, budget: integer) Works_on (eid: integer, pid: integer) Manger (mid: integer, mname: string, deptid: integer) The meaning of these relations is straightforward; for example, Works_on has one record per Employee-Project pair such that the Employee Works_on the Project. 1. Write the SQL statements required to create these relations, including appropriate versions of all primary and foreign key integrity...

  • Consider the following two Relational Schema describing the EMPLOYEES and DEPARTMENTS of some organization (assume all...

    Consider the following two Relational Schema describing the EMPLOYEES and DEPARTMENTS of some organization (assume all names are unique). EMPLOYEES (EmployeeName, Salary, DeptName) DEPARTMENTS (DeptName, ManagerName, City) Define at schema level, a constraint (SQL Assertion) which specifies that none of the salaries of the employees of any department located in ‘San Francisco’ is more than the salary of any employee in the ‘Management’ department.

  • Given the following relational schema, write queries in SQL to answer the English questions. There is...

    Given the following relational schema, write queries in SQL to answer the English questions. There is a shipment database on the MySQL server. You can also use the DDL for MySQL. You must only submit the SQL for your answers but you can include the query output as well to help the TA with marking. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid: integer, shipdate: Date/Time) ShippedProduct(sid:...

  • can you answer part e of the question Q.31 Answer the following questions (a) Explain difference between lossy decomposition and lossless decomposition (b) If you write a SQL statement to inner jo...

    can you answer part e of the question Q.31 Answer the following questions (a) Explain difference between lossy decomposition and lossless decomposition (b) If you write a SQL statement to inner join the following two tables based on Plocation value as inner join condition, is the result table lossy or lossless? (Explain why?) EMP LOCS P.K EMP PROJ1 Hours Pname Plocation Р.К. (c) Given a relation schema R ={SSN, Ename, Pnumber, Pname, Plocation, Hours) R is decomposed to R1, R2,...

  • Given the following relational schema, write queries in SQL to answer the English questions. There is...

    Given the following relational schema, write queries in SQL to answer the English questions. There is a shipment database on the MySQL server. You can also use the DDL for MySQL. You must only submit the SQL for your answers but you can include the query output as well to help the TA with marking. Customer(cid: integer, cname: string, address: string, city: string, state: string) Product(pid: integer, pname: string, price: currency, inventory: integer) Shipment(sid: integer, cid: integer, shipdate: Date/Time) ShippedProduct(sid:...

  • Answer the following five (5) questions, based on the schema provided.

    C. Answer the following five (5) questions, based on the schema provided.Consider the following schema:Supplier (sid: integer, sname: string, address: string)Part(pid: integer, pname: string, , color: string)Catalog(sid: integer, pid: integer, cost: real)The relation Supplier stores suppliers and the primary key of that relation is sid. The relation Part stores parts, and pid is the primary key of that relation. Finally, Catalog stores which supplier supplies which part and at which cost (price). The primary key is the combination of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT