Question

In: Computer Science

Consider the schemas of the following relational database for a company. The company has different departments...

Consider the schemas of the following relational database for a company. The company has different departments at different cities in different states:

employee(employee-id, dept-id, name, street-num, street-name, city, state, zip, salary)

department(dept-id, dept-name, city, state)

manager(manager-id, employee-id)

NOTES:

manager-id in the manager relation is a foreign key to the employee relation.

employee-id in the manager relation is a foreign key to the employee relation.

dept-id in the employee relation is a foreign key to the department relation.

An employee belongs to a single manager only. That is, an employee only works for one manager. Some employees do not have a manager (in that case, they do not have an entry in the manager relation).

Write SQL statement (no computer work is needed) for each of the following queries.

  1. Find all managers (manager-ids and names) who’s department located in California (state = ‘CA’).
  1. Find all employees (IDs and names) in the database who do not work for the Research Department.
  1. Anita Jones got married and she wanted to change her name to Anita Smith. Modify the database so that Anita Jones becomes Anita Smith (her employee-id is 987654321).
  1. Delete all tuples in the manager relation for manager-id = 123456789.

Solutions

Expert Solution

Ans 1).

Select MANAGER.manager-id, EMPLOYEE.name from MANAGER NATURAL JOIN EMPLOYEE NATURAL JOIN DEPARTMENT WHERE DEPARTMENT.state="CA";

In order to fetch the manager ID and name of manager who is also the employee of the company then the interrelation of three table has been needed as MANAGER table is associated with EMPLOYEE table with the employee ID field and EMPLOYEE table in associated with DEPARTMENT table with department ID field.

Along with that, condition is applied in WHERE clause in which DEPARTMENT.STATE is CA(California).

Ans 2).

SELECT employee.employee-id, employee.name from MANAGER NATURAL JOIN EMPLOYEE NATURAL JOIN DEPARTMENT WHERE DEPARTMENT.dept-name!="Research";

In order to find the employee ID and employee name then the interrelation of three table has been needed as MANAGER table is associated with EMPLOYEE table with the employee ID field and EMPLOYEE table in associated with DEPARTMENT table with department ID field.

Along with that, condition is applied in WHERE clause in which DEPARTMENT.dept-name is not equals to "Research";

Ans 3).

UPDATE EMPLOYEE SET name="Anita Smith" where employee-id=987654321;

In order to update the name of Anita Jones to Anita Smith then UPDATE keyword is used and the command has been written as above in this update keyword is used along with the table name and then the SET KEYWORD is used.

The updation column is written along with the condition in which the updation has to be needed.

Ans 4).

DELETE FROM MANAGER where manager-id=123456789;

IN ORDER TO DELETE ALL THE TUPLES FROM THE MANAGER TABLE THEN DELETE KEYWORD IS USED.

DELETE keyword is used in order to delete the row of a table whether DROP table is used to delete the entire table and DROP word in ALTER command is used in order to modify the constraint for the the column of a particular table or its datatype.

So in order to delete multiple of manager table where manager ID is 123456789 the above command has to be implemented.


Related Solutions

• Relational Schema Create a relational database schema consisting of the four relation schemas representing various...
• Relational Schema Create a relational database schema consisting of the four relation schemas representing various entities recorded by a furniture company.   Write CREATE TABLE statements for the following four relation schemas. Define all necessary attributes, domains, and primary and foreign keys. Customer(CustomerID, Name, Address) FullOrder(OrderID, OrderDate, CustomerID) Request(OrderID, ProductID, Quantity) Product(ProductID, Description, Finish, Price) You should assume the following: Each CustomerID is a number with at most three digits, each OrderID is a number with at most five digits,...
The following tables form part of a database (Flights Database) held in a relational DBMS: employee...
The following tables form part of a database (Flights Database) held in a relational DBMS: employee (empNo, empName, empSalary, empPosition) aircraft (aircraftNo, acName, acModel, acFlyingRange) flight (flightNo, aircraftNo, fromAirport, toAirport, flightDistance, departTime, arriveTime) certified (empNo, aircraftNo) Where:  employee contains details of all employees (pilots and non-pilots) and empNo is the primary key;  aircraft contains details of aircraft and C is the primary key.  flight contains details of flights and (flightNo, aircraftNo) form the primary key.  certified...
You are given the following schemas for a corporation database. The corporation owns several subsidiary companies...
You are given the following schemas for a corporation database. The corporation owns several subsidiary companies (e.g. Disney Corporation owns Lucasfilm Ltd). Managers are also Employees. Answer the following questions using the schemas. Employee(ssn, name, street, city) Company(company_name, asset) Company_Branches(company_name, branch_num, city) Works(ssn, company_name, branch_num, salary) Managed_By(ssn, manager_ssn) 6) Does the current design allow us to enforce the constraint that each employee must have a manager (without using external check or triggers)? Why or why not? 7) If the answer...
The database design process for noSQL databases is different from one for relational (SQL) databases. As...
The database design process for noSQL databases is different from one for relational (SQL) databases. As we learned noSQL database does not require to have a predefined structure, except of creating a list of databases and the list of collections. Some of the noSQL databases (like MongoDB) allow to define certain rules that will define what should be the structure of the acceptable documents for each collection. As you may recall, when you need to store multiple data points in...
Describe what a database system is and how it is used. What is a relational database...
Describe what a database system is and how it is used. What is a relational database system and how used in a company to benefit an organization? What does it mean to run a query?
QUESTION: The following tables describe the content of a relational database: a) Identify and classify the...
QUESTION: The following tables describe the content of a relational database: a) Identify and classify the tables as either entity or relationship The first step in building an E-R model is to identify the entities. Having identified the entities, the next step is to identify all the relationships that exist between these entities. Using the content of the relational database above: b) Using the relations in the relational database, explain how one can transform relationship in E-R model into a...
What are some of the advantages of a relational database system?
What are some of the advantages of a relational database system?
Case Study 4 A relational database is to be designed for a medium sized Company dealing...
Case Study 4 A relational database is to be designed for a medium sized Company dealing with industrial applications of computers. The Company delivers various products to its customers ranging from a single application program through to complete installation of hardware with customized software. The Company employs various experts, consultants and supporting staff. All personnel are employed on long‐ term basis, i.e. there is no short‐term or temporary staff. Although the Company is somehow structured for administrative purposes (that is,...
Define the four main types of relational constraints and use the example relational database (Figure 1)...
Define the four main types of relational constraints and use the example relational database (Figure 1) to illustrate each of these constraints. Figure 1 House(MLS, Addr, NumRooms, NumBedRooms, SellID, OfficeID, Price) Seller(SellID, Name) PotentialBuyer(BuyID, Name) REOffice(OffID, Name, Addr, Phone) Agent(AgID, OffID, Name) Showing(AgID, MLS, BuyID, Date)
Data Modeling and Database Design (Database Concepts, Eighth Edition) The relational model is the most important...
Data Modeling and Database Design (Database Concepts, Eighth Edition) The relational model is the most important standard in database processing today. Why do you feel that this model has continued to be successful in the world of IT? What would happen if large corporations decided to reject this theory, and store their data using a non-relational model? Are there any success stories where this has happened?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT