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),
Salary decimal(10,2),
super_ssn char(9),
dno int,
primary key (Ssn),
foreign key (dno) references department(Dnumber));
insert into EMPLOYEE values ( 'John', 'B', 'Smith', '123456789',
'09-Jan-1965', '731 Fondren, Houston, TX', 'M', '30000',
'333445555', '5' );
insert into EMPLOYEE values ( 'Franklin', 'T', 'Wong', '333445555',
'08-Dec-1955', '638 Voss, Houston, TX', 'M', '40000', '888665555',
'5' );
insert into EMPLOYEE values ('Alicia', 'J', 'Zelaya', '999887777',
'19-Jan-1968', '3321 Castle, Spring, TX', 'F', '25000',
'987654321', '4' );
insert into EMPLOYEE values ('Jennifer', 'S', 'Wallace',
'987654321', '20-Jun-1941', '291 Berry, Bellaire, TX', 'F',
'43000', '888665555', '4');
insert into EMPLOYEE values ('Ramesh', 'K', 'Narayan', '666884444',
'15-Sep-1962', '975 Fire Oak, Humble, TX', 'M', '38000',
'333445555', '5');
insert into EMPLOYEE values ('Joyce', 'A', 'English', '453453453',
'31-Jul-1972', '5631 Rice, Houston, TX', 'F', '25000', '333445555',
'5');
insert into EMPLOYEE values ('Ahmad', 'V', 'Jabbar', '987987987',
'29-Mar-1969', '980 Dallas, Houston, TX', 'M', '25000',
'987654321', '4');
insert into EMPLOYEE values ('James', 'E', 'Borg', '888665555',
'10-Nov-1937', '450 Stone, Houston, TX', 'M', '55000', NULL,
'1');
alter table employee add (foreign key(super_ssn) references
employee(ssn));
alter table department add (foreign key(mgr_ssn) references
employee(ssn));
drop table DEPT_LOCATIONS cascade constraints;
create table DEPT_LOCATIONS (
Dnumber int not null,
Dlocation varchar2(15) not null,
primary key (Dnumber, Dlocation),
foreign key(Dnumber) references department(dnumber));
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');
drop table project cascade constraints;
create table project (
Pname varchar2(15) not null,
Pnumber int not null,
Plocation varchar2(15),
Dnum int not null,
primary key (Pnumber),
unique (Pname),
foreign key(Dnum) references department(Dnumber));
insert into PROJECT values ('ProjectX', '1', 'Bellaire',
'5');
insert into PROJECT values ('ProjectY', '2', 'Sugarland',
'5');
insert into PROJECT values ('ProjectZ', '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');
drop table works_on cascade constraints;
create table works_on (
Essn char(9) not null,
Pno int not null,
hours decimal(3,1),
primary key(essn, pno),
foreign key(Essn) references employee,
foreign key(pno) references project);
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', NULL);
drop table dependent cascade constraints;
create table dependent (
essn char(9) not null,
dependent_name varchar2(15) not null,
Sex char(1),
Bdate date,
relationship varchar2(8),
primary key(essn, dependent_name),
foreign key(essn) references employee);
insert into DEPENDENT values ('333445555', 'Alice', 'F',
'05-Apr-1986', 'Daughter');
insert into DEPENDENT values ('333445555', 'Theodore', 'M',
'25-Oct-1983', 'Son');
insert into DEPENDENT values ('333445555', 'Joy', 'F',
'03-May-1958', 'Spouse');
insert into DEPENDENT values ('987654321', 'Abner', 'M',
'28-Feb-1942', 'Spouse');
insert into DEPENDENT values ('123456789', 'Michael', 'M',
'04-Jan-1988', 'Son');
insert into DEPENDENT values ('123456789', 'Alice', 'F',
'30-Dec-1988', 'Daughter');
insert into DEPENDENT values ('123456789', 'Elizabeth', 'F',
'05-May-1967', 'Spouse');
This demonstration is using Oracle Live SQL.
1.Stored Procedure :
create procedure update_superSSN(empSSN in
employee.SSN%type,
new_superSSN in employee.super_ssn%type)
as
begin
update employee set super_ssn=new_superSSN where ssn=empSSN;
end;
Executing stored procedure :
exec update_superSSN('123456789','333445555');
Employee table :
*******************************
2.Function :
create function NumOfEmployee_ByDept(deptname varchar2)
return number
is
numEmp number(2):=0;
begin
select count(ssn) into numEmp from employee where dno=(select
dnumber from department where
dname=deptname);
return numEmp;
end;
Calling function :
select dname,NumOfEmployee_ByDept(dname) from department;
Screen in Oracle Live SQL :
drop table department cascade constraints; create table department ( Dname varchar2(15) not null, Dnumber int not...
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...
I need help with the following SQL query for a company database (script given below). The name of the Department. The number of employees working in that department. The number of different projects controlled by this department. The name of the project controlled by this department that has the maximum number of employees of the company working on it. The number of the above project. The cumulative sum of the number of employees of the company working on the projects...
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...
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...
(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...
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...
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...
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...
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...