Question

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 key integrity constraints.

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

4. Write an SQL statement to add John Doe as an employee with eid = 101, age = 32 and salary = 15,000.

5. Write an SQL statement to give every employee a 10 percent raise.

6. Write an SQL statement to delete the Toy department.

Question 2 (5 points). Consider the following schema:

Suppliers( sid: integer, sname: string, address: string)

Parts(pid: integer, pname: string, color: string)

Catalog( sid: integer, pid: integer, cost: real)

The Catalog relation lists the prices charged for parts by Suppliers. Write the following

queries in SQL:

1. Find the pnames of parts for which there is some supplier.

2. Find the snames of suppliers who supply every part.

3. Find the snames of suppliers who supply every red part.

4. Find the pnames of parts supplied by Acme Widget Suppliers and no one else.

5. Find the sids of suppliers who supply only red parts.

6. Find the sids of suppliers who supply a red part and a green part.

7. Find the sids of suppliers who supply a red part or a green part.

Question 3 (5 points). The following relations keep track of airline flight information:

Write the following queries in SQL:

For each pilot who is certified for more than three aircraft, find the eid and the maximum cruisingrange of the aircraft for which she or he is certified.

Find the names of pilots whose salary is less than the price of the cheapest route from Los Angeles to Honolulu.

Find the aids of all aircraft that can be used on routes from Los Angeles to Chicago.

Print the names of employees who are certified only on aircrafts with cruising range longer than 1000 miles.

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

Question 1

  1. These foreign key constaints are necessary:
    Works : FOREIGN KEY did REFERENCES Dept(did)
    Dept: FOREIGN KEY managerid REFERENCES Emp(eid)
  2. CREATE TABLE Emp ( eid INT, ename VARCHAR, age INT, salary REAL, PRIMARY KEY (eid) );
    CREATE TABLE Dept ( did INT PRIMARY KEY, dname VARCHAR, budget REAL, managerid INT, FOREIGN KEY (managerid) REFERENCES Emp(eid) );
    CREATE TABLE Works ( eid INT, did INT, pet_time INT, PRIMARY KEY (eid, did), FOREIGN KEY (eid) REFERENCES Emp(eid) ON DELETE CASCADE, FOREIGN KEY (did) REFERENCES Dept(did) ON DELETE CASCADE);
  3. managerId INT NOT NULL
  4. INSERT INTO Emp VALUES(101,'John Doe', 32, 15000.0);
Add a comment
Know the answer?
Add Answer to:
Any help appreciated! Question 1 (5 points). Answer each of the following questions briefly. The questions...
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
  • Please finish all parts, thanks! 2) Consider the following schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid:integer, pname: string, color: string ) Catalog( sid: integer, pid...

    Please finish all parts, thanks! 2) Consider the following schema: Suppliers(sid: integer, sname: string, address: string) Parts(pid:integer, pname: string, color: string ) Catalog( sid: integer, pid: integer, cost: real) Write the following queries in relational algebra. a) Find the names of suppliers who supply some red part b) Find the sids of suppliers who supply some red or green part c) Find the sids of suppliers who supply some red and some green part. d) Find the sids of suppliers...

  • EXERCISE 1 (SQL Queries) Consider the following schema: SUPPLIERS (SID : integer, SNAME : string, CITY...

    EXERCISE 1 (SQL Queries) Consider the following schema: SUPPLIERS (SID : integer, SNAME : string, CITY : string) PARTS (PID : integer, PNAME : string, COLOR : string) CATALOG (SID : integer, PID : integer, COST : real) The key fields are underlined, and the domain of each field is listed after the field name. Thus, SID is the key for SUPPLIERS, PID is the key for PARTS, and SID and PID together form the key for CATALOG. The CATALOG...

  • 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...

  • SQL Queries (1)

    Suppliers(sid: integer, sname: string, address:string)Parts(pid: integer, pname: string, color: string)Catalog(sid: integer, pid: integer, cost: real)The Catalog relation lists the prices charged for parts bySuppliers. Write the following queries in SQL:1) Find the pnames of parts supplied by Acme Widget Suppliers andno one else.2) Find the sids of suppliers who charge more for some partthan the average cost of that part (averaged over all the supplierswho supply that part).3) For each part, find the sname of the supplier who chargesthe most...

  • Consider the following schema: SUPPLIERS (SID: integer, SNAME: string, STREET: string, CITY: string, ZIP: string) PARTS...

    Consider the following schema: SUPPLIERS (SID: integer, SNAME: string, STREET: string, CITY: string, ZIP: string) PARTS (PID: integer, PNAME: string, COLOR: string) CATALOG (SID: integer, PID: integer, COST: real) The primary key attributes are underlined, and the domain of each attribute is listed after the attribute name. Thus, SID is the primary key for SUPPLIERS, PID is the primary key for PARTS, and SID and PID together form the primary key for CATALOG. Attribute SID in CATALOG is a foreign...

  • 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...

  • In .sql Given the following relational schemas, answer the following questions: Suppliers(sid: int, sname: VARCHAR(30), address:...

    In .sql Given the following relational schemas, answer the following questions: Suppliers(sid: int, sname: VARCHAR(30), address: VARCHAR(50)) Parts(pid: int, pname: VARCHAR(30), color: VARCHAR(10)) Catalog(sid: int, pid: int, cost: double) c. (8 points) List sid, sname, and address of all suppliers who supply at least one part. In other words, the answer must not show sid and sname of any supplier who does not have its sid in the Catalog table d. (4 points) Find all distinct black parts in the...

  • consider the following relational database that records details of parts and suppliers. Primary keys are underlined...

    consider the following relational database that records details of parts and suppliers. Primary keys are underlined and the Foreign Keys are identified with (FK). Suppliers (sid, sname, address, credit) Parts (pid, pname, color) Catalog (sid (FK), pid (FK), cost) The credit attribute denotes the size of the supplier’s credit account. The Catalog relation lists the prices charged for parts by Suppliers. Which of the following queries returns the snames of suppliers who supply every part? Select one or more: a....

  • Problem 1 Consider the following relations containing airline flight information, where the keys are underlined ghts(no:...

    Problem 1 Consider the following relations containing airline flight information, where the keys are underlined ghts(no: integer, from: string, to: string, distance: integer, departs: time, arrives: time) aircraftlaid: integer, aname: string, crusingrange: integer) certified(eid: integer,aid: integer) employees(eid: integer, ename: string, salary: integer) Note that the employees relation describes pilots and other kinds of employees as well; every pilot is certified for some aircraft (otherwise, he or she would not qualify as a pilot), and only pilots are certified to fly....

  • 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...

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