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,...
Question 2: consider the following library relational database schema Write a program segment to retrieves the...
Question 2: consider the following library relational database schema Write a program segment to retrieves the list of books that became overdue yesterday and that prints the book title and borrower name for each. 1- Use JDBC with Java as the host language
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...
research Amazon’s in-house relational database AWS. Consider some of the following questions. How does Amazon approach...
research Amazon’s in-house relational database AWS. Consider some of the following questions. How does Amazon approach its database solution? Why did Amazon develop its own database solution? How important is reliability to Amazon, and what challenges do they face? What is Dynamo? What techniques does it involve? How does Dynamo handle failure? Does it rely on redundancy? What are your personal experiences with Amazon’s reliability?
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?
Consider the following relational database schema:             employee(employee-name, employee-id, street, e-city)             works(employee-
Consider the following relational database schema:             employee(employee-name, employee-id, street, e-city)             works(employee-id, company-id, salary)             company(company-name, company-id, c-city)             manages(employee-id, manager-id) Specify the following queries on this database schema using the relational operators we discussed in class. Write your answers on a separate sheet of paper in the order that they are specified below. Retrieve the name and address of employees who work for First Bank Corporation. Retrieve the name, street address, and city of residence of all employees...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT