I need help with the following SQL query for a company database (script given below).
Script file given:
--------------------------------------------------------------------------------
/* Company database SQL data definition. Ordering of tables is important since a table can reference tables that are defined before. Since date type is not available in MS_SQL, create a new user defined data type date as char(10). */ /* Phase 1: Drop all six tables of Company database if they exist in the correct sequence without violating foreign key constraints */ -- if dependent table already exists, remove the table drop table IF EXISTS dependent; -- if works_on table already exists, remove the tablema drop table IF EXISTS works_on; -- if project table already exists, remove the table drop table IF EXISTS project; -- if dept_locations table already exists, remove the table drop table IF EXISTS dept_locations; -- if employee table already exists, remove the table drop table IF EXISTS employee; -- if department table already exists, remove the table drop table IF EXISTS department; /* Phase 2: Create all six empty tables of Company database */ -- create a new empty table department create table department ( dname varchar(15) not null, dnumber int not null, mgrssn char(9) not null, mgrstartdate char(10), constraint deptpk primary key (dnumber), constraint deptsk unique (dname) /*constraint deptmgrfk foreign key (mgrssn) references employee(ssn) This foreign key has been commented out since the dbms does not support mutual foreign keys between department and employee tables */ ); -- create a new empty table employee create table employee ( fname varchar(15) not null, minit char, lname varchar(15) not null, ssn char(9) not null, bdate char(10), address varchar(30), sex char, salary decimal(10,2), superssn char(9), dno int not null, constraint emppk primary key (ssn), /*constraint empsuperfk foreign key (superssn) references employee(ssn), This foreign key constraint among columns of the same table has not been supported by most SQL systems */ constraint empdeptfk foreign key (dno) references department(dnumber) ); -- create a new empty table dept_locations create table dept_locations ( dnumber int not null, dlocation varchar(15) not null, constraint dlocpk primary key (dnumber, dlocation), constraint dlocdeptfk foreign key (dnumber) references department(dnumber) ); -- create a new empty table project create table project ( pname varchar(15) not null, pnumber int not null, plocation varchar(15), dnum int not null, constraint projpk primary key (pnumber), constraint projsk unique (pname), constraint projdeptfk foreign key (dnum) references department(dnumber) ); -- create a new empty table works_on create table works_on ( essn char(9) not null, pno int not null, hours decimal(3,1) not null, constraint workpk primary key (essn, pno), constraint workempfk foreign key (essn) references employee(ssn), constraint workprojfk foreign key (pno) references project(pnumber) ); -- create a new empty table dependent create table dependent ( essn char(9) not null, dependent_name varchar(15) not null, sex char, bdate char(10), relationship varchar(8), constraint deppk primary key (essn, dependent_name), constraint depempfk foreign key (essn) references employee(ssn) ); /* Phase 3: Add rows of data to each of these six empty tables of Company DB */ -- Insertion of three department rows INSERT INTO department VALUES ('Research','5','333445555','1988-05-22'); INSERT INTO department VALUES ('Administration','4','987654321','1995-01-01'); INSERT INTO department VALUES ('Headquarters','1','888665555','1981-06-19'); -- Insertion of eight employee rows INSERT INTO employee VALUES ('James','E','Borg','888665555','1937-11-10','450 Stone, Houston, TX','M','55000','','1'); INSERT INTO employee VALUES ('Franklin','T','Wong','333445555','1955-12-08','638 Voss, Houston, TX','M','40000','888665555','5'); INSERT INTO employee VALUES ('Jennifer','S','Wallace','987654321','1941-06-20','291 Berry, Bellaire, TX','F','43000','888665555','4'); INSERT INTO employee VALUES ('John','B','Smith','123456789','1965-01-09','731 Fondren, Houston, TX','M','30000','333445555','5 '); INSERT INTO employee VALUES ('Ramesh','K','Narayan','666884444','1962-09-15','975 Fire Oak, Humble, TX','M','38000','333445555','5'); INSERT INTO employee VALUES ('Joyce','A','English','453453453','1972-07-31','5631 Rice, Houston, TX','F','25000','333445555','5'); INSERT INTO employee VALUES ('Alicia','J','Zelaya','999887777','1968-01-19','3321 Castle, Spring, TX','F','25000','987654321','4'); INSERT INTO employee VALUES ('Ahmad','V','Jabbar','987987987','1969-03-29','980 Dallas, Houston, TX','M','25000','987654321','4'); -- Insertion of five dept_locations rows INSERT INTO dept_locations VALUES ('1','Houston'); INSERT INTO dept_locations VALUES ('4','Stafford'); INSERT INTO dept_locations VALUES ('5','Bellaire'); INSERT INTO dept_locations VALUES ('5','Sugarland'); INSERT INTO dept_locations VALUES ('5','Houston'); -- Insertion of six project rows INSERT INTO project VALUES ('ProductX','1','Bellaire','5'); INSERT INTO project VALUES ('ProductY','2','Sugarland','5'); INSERT INTO project VALUES ('ProductZ','3','Houston','5'); INSERT INTO project VALUES ('Computerization','10','Stafford','4'); INSERT INTO project VALUES ('Reorganization','20','Houston','1'); INSERT INTO project VALUES ('Newbenefits','30','Stafford','4'); -- Insertion of sixteen works_on rows INSERT INTO works_on VALUES ('123456789','1','32.5'); INSERT INTO works_on VALUES ('123456789','2','7.5'); INSERT INTO works_on VALUES ('666884444','3','40.0'); INSERT INTO works_on VALUES ('453453453','1','20.0'); INSERT INTO works_on VALUES ('453453453','2','20.0'); INSERT INTO works_on VALUES ('333445555','2','10.0'); INSERT INTO works_on VALUES ('333445555','3','10.0'); INSERT INTO works_on VALUES ('333445555','10','10.0'); INSERT INTO works_on VALUES ('333445555','20','10.0'); INSERT INTO works_on VALUES ('999887777','30','30.0'); INSERT INTO works_on VALUES ('999887777','10','10.0'); INSERT INTO works_on VALUES ('987987987','10','35.0'); INSERT INTO works_on VALUES ('987987987','30','5.0'); INSERT INTO works_on VALUES ('987654321','30','20.0'); INSERT INTO works_on VALUES ('987654321','20','15.0'); INSERT INTO works_on VALUES ('888665555','20','0.0'); -- Insertion of seven dependent rows INSERT INTO dependent VALUES ('333445555','Alice','F','1986-04-05','daughter'); INSERT INTO dependent VALUES ('333445555','Theodore','M','1983-10-25','son'); INSERT INTO dependent VALUES ('333445555','Joy','F','1958-05-03','spouse'); INSERT INTO dependent VALUES ('987654321','Abner','M','1942-02-28','spouse'); INSERT INTO dependent VALUES ('123456789','Michael','M','1988-01-04','son'); INSERT INTO dependent VALUES ('123456789','Alice','F','1988-12-30','daughter'); INSERT INTO dependent VALUES ('123456789','Elizabeth','F','1967-05-05','spouse'); /* End of Company database script */
select dname from department
Research |
Administration |
Headquaters |
select dname,count(*) from department,empolyee where department.dnumber=employee.dno Group by dname
dname | count(*) |
Research | 4 |
Administration | 3 |
Headquaters | 1 |
I need help with the following SQL query for a company database (script given below). The...
Query #2: List the name of the project and total number of hours worked on by all the employees on this project, also report the number of employees working on each project. Database: //STEP #1: CREATE TABLE employee ( fname varchar(15) not null, minit varchar(1), lname varchar(15) not null, ssn char(9), bdate date, address varchar(50), sex char, salary decimal(10,2), Super_ssn char(9), dno char(4), primary key (ssn)); CREATE TABLE department ( dname varchar(25) not null, dnumber char(4), Mgr_ssn char(9) not null,...
Query 1: Retrieve names of all the projects as well as First and Last name of managers if they are working on any of these projects. Database: //STEP #1: CREATE TABLE employee ( fname varchar(15) not null, minit varchar(1), lname varchar(15) not null, ssn char(9), bdate date, address varchar(50), sex char, salary decimal(10,2), Super_ssn char(9), dno char(4), primary key (ssn)); CREATE TABLE department ( dname varchar(25) not null, dnumber char(4), Mgr_ssn char(9) not null, Mgr_start_date date, primary key (dnumber)); CREATE...
drop table department cascade constraints; create table department ( Dname varchar2(15) not null, Dnumber int not null, Mgr_ssn char(9) not null, mgr_start_date Date, primary key (Dnumber), Unique (Dname)); insert into DEPARTMENT values ('Research', '5', '333445555', '22-May-1988'); insert into DEPARTMENT values ('Administration', '4', '987654321', '01-Jan-1995'); insert into DEPARTMENT values ('Headquarters', '1', '888665555', '19-Jun-1981'); drop table employee cascade constraints; create table employee ( Fname varchar2(15) not null, Minit char(1), Lname varchar2(15) not null, Ssn char(9), Bdate date, Address varchar2(30), Sex char(1),...
NEED HELP IN INSERT STATEMENTS FOR THE TABLES CAN YOU PLEASE ADD SOME INSERT STATEMENTS FOR A COMPANY SCHEMA SCRIPT. PLEASE ADN THANK YOU DROP TABLE dependent; DROP TABLE works_on; DROP TABLE project; DROP TABLE dept_locations; DROP TABLE department; DROP TABLE employee; CREATE TABLE employee ( fname varchar(15) not null, minit varchar(1), lname varchar(15) not null, ssn char(9), bdate date, address varchar(50), sex char, salary numeric(10,2), superssn char(9), dno numeric, primary key (ssn), foreign key (superssn) references employee(ssn) ); CREATE...
(SELECT pnumber FROM project, department, employee WHERE dnum=dnumber AND mgr_ssn=ssn AND lname='Smith') UNION (SELECT pnumber FROM project, works_on, employee WHERE pnumber=pno AND essn=ssnAND lname='Smith') Can you draw the relation step by step , how to solve it ?! Figure 5.6 One possible database state for the COMPANY relational database schema. EMPLOYEE Sex Salary Super ssn Dno B Smith 123456789 1965-01-09 731 Fondren, Houston, TX M 30000 3334455555 Ssn Fname Minit Lname John Franklin TWong 333445555 1955-12-08 638 Voss, Houston, TXM40000...
Search all employee who work total on all project less than 40 hrs from works_on table. Please give me a query for this. Figure 5.6 One possible database state for the COMPANY relational database schema. EMPLOYEE Fname Minit Lname Sex Salary Super ssn Dno B Smith 123456789 1965-01-09 731 Fondren, Houston, TX M 30000 333445555 5 FranklinT Wong 333445555 1955-12-08 638 Voss, Houston, TX M 40000 888665555 5 JZelaya 999887777 1968-01-19 3321 Castle, Spring, TX F 25000 9876543214 JenniferSWallace 9876543211941-06-20...
Use the tables in the next page to answer the following questions in SQL. 1. Print the names of employees who work in a project located in Houston. 2. Print the names of employees with no dependents. 3. Print the names of employees who are managers. 4. Print the names of employees who have more than one wife. 5. Print the names of employees who work in all the projects. EMPLOYEE Frame John Franklin Minit B T S K A...
Please provide the relation algebra, the oracle SQL code and the output tuples for the following (Answer #6 only the BONUS question). I have the others actually I have the BONUS, but I want to compare with your solution to make sure I did it correctly. Thank you very much! LAB exercises 2 Write the Oracle DML query codes for the following questions and take the screen shot of the output. 1. Retrieve the name and address of all employees...
Q2. Retrieve the names of all employees from the employee table to produce output on CSV format or delimited format with a common delimeter, rather than separete columns. Hint:Put the whole row into a string with a semicolon as the seperator(delimeter) between thecolumns: FORMAT:(fname;minit;lname) Example: EMPLOYEES -------------- James;E;Borg Frank;T;Wong Q3. Write a query to show the employees name from the employee table in this format: first letter of the first name, followed by a dot, a blank, and the full...
New to DB's Please help! You are designing and creating a database named COMPANY for an HR (Human Resource) Dept of a Software Consulting Company to manage their employees and their assigned work (projects) in the company First Step to Design and Create a Database is Creating an E-R Diagram by Identifying Entities, Attributes and Relationships between any two Entities to Create a Company Database Scheme. 1. Create an E-R Diagram for the Company database from the raw data files...