University Database Modeling and Design Practical Assignment - MIS602

Verified

Added on  2022/08/28

|11
|1429
|21
Practical Assignment
AI Summary
This document presents a comprehensive solution to a database modeling assignment. The assignment involves creating three database tables: department, employee, and salary, with appropriate keys and data types. The solution includes SQL queries for creating these tables, inserting records into each table, and populating them with sample data. Various SQL queries are provided to retrieve and manipulate the data, including displaying employee information, names, and job titles. The solution also covers queries to find unique job titles, increase salaries, retrieve employees with minimum and maximum salaries, and filter employees based on salary ranges and job titles. Additionally, the solution demonstrates queries for updating salaries, deleting records, counting employees, and finding employees based on specific criteria like address and date of joining. The assignment is designed to provide hands-on experience in database design and SQL query writing.
Document Page
Running head: DATABASE MODELLING
Database Modelling
Name of the Student
Name of the University
Author Note
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1
DATABASE MODELLING
Task 1: Create three tables with relevant keys as suggested in the above diagram
CREATE TABLE department (
Department_id int(11) NOT NULL,
Deptname varchar(30) NOT NULL,
DeptLocation varchar(20) NOT NULL,
DeptFloor varchar(20) NOT NULL,
PRIMARY KEY (Department_id));
CREATE TABLE employee(
employee_id int(11) NOT NULL,
Empname varchar(25) NOT NULL,
Managerid int(11) NOT NULL,
Dateofhire date NOT NULL,
Jobname varchar(15) NOT NULL,
Salary decimal(10,2) NOT NULL,
Department_id int(11) NOT NULL,
DOB date NOT NULL,
Address varchar(30) NOT NULL,
PRIMARY KEY (employee_id),
FOREIGN KEY (Department_id) REFERENCES Department(Department_id));
CREATE TABLE salary(
salary_level int(11) NOT NULL,
Salarymin int(11) NOT NULL,
Salarymax int(11) NOT NULL,
PRIMARY KEY (salary_level));
Task 2: Insert record of 10 employees in the employee table. However for inserting in
employee table will invoke foreign key constraint as there are no data about departments.
Hence, first depart table will be populated with data.
INSERT INTO department (Department_id, Deptname, DeptLocation,
DeptFloor) VALUES
(2011, 'DEVELOPMENT', 'Hobart', '7th'),
(2012, 'ANALYST', 'Melobourne', '12th'),
(2013, 'TECHNICAL', 'Sydney', '1th'),
(2014, 'HUMAN RESOURCES', 'Perth', '5th'),
Document Page
2
DATABASE MODELLING
(2015, 'ACCOUNTS', 'Brisbane', '1st');
Task 3: As department table is already populated in previous task. Next employee tbale will
be populated.
INSERT INTO employee (employee_id, Empname, Managerid, Dateofhire,
Jobname, Salary, Department_id, DOB, Address) VALUES
(1001, 'James', 5091, '2019-10-15', 'PROGRAMMER', '65500.00', 2011,
'1995-10-08', 'Hobart'),
(1003, 'Minie', 5095, '2019-07-23', 'TECHNICIAN', '99000.00', 2012,
'1995-10-22', 'Melobourne'),
(1002, 'Flynn', 5092, '2017-10-08', 'PROGRAMMER', '45000.00', 2011,
'2000-10-16', 'Melobourne'),
(1004, 'Kane', 5093, '2012-10-16', 'MANAGER', '95000.00', 2013,
'2001-01-17', 'Melobourne'),
(1006, 'Smith', 5094, '2013-04-08', 'ANALYST', '99500.00', 2014,
'1993-12-17', 'Brisbane'),
(1005, 'Wilson', 5096, '2016-05-09', 'ACCOUNTANT', '95050.00', 2013,
'1998-12-18', 'Queens'),
(1007, 'Robert', 5096, '2015-10-15', 'PROGRAMMER', '75000.00', 2011,
'1999-02-25', 'Brisbane'),
(1009, 'Nick', 5092, '2015-12-06', 'ACCOUNTANT', '65000.00', 2013,
'1997-06-06', 'Havana Avenue'),
(1008, 'Samuel', 5097, '2015-10-02', 'ACCOUNTANT', '59050.00', 2013,
'1992-12-12', 'Brisbane'),
(1010, 'Vencie', 5096, '2012-12-12', 'MANAGER', '55500.00',
2015, '1996-04-18', 'St George Avenue');
Task 4: Insert record of 5 salary levels in the salary table
INSERT INTO salary (salary_level, Salarymin, Salarymax) VALUES
(1, 15000, 29999),
(2, 30000, 44999),
(3, 45000, 54999),
(4, 55000, 94999),
(5, 95000, 99999);
Document Page
3
DATABASE MODELLING
Task 5: Write a query to display the information about the employees in the employee table.
select * from employee;
Task 6: Write a query to display the name of all the employees
select empname from employee;
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4
DATABASE MODELLING
Task 7: Write a query to display the name of all the employees and their jobname.
select empname, Jobname from employee;
Task 8: Write a query in SQL to display the unique jobname for all the employees.
select DISTINCT(jobname) from employee;
Task 9: Write a query to increase the salary for all the employees by 12%. Display the
empname, jobname and salary after the increment.
update employee
Document Page
5
DATABASE MODELLING
set salary = (Salary*(12/100)+Salary);
Task 10: Write a query to display the employee names with minimum and maximum salary.
select Empname, salary from employee
where salary = (select min(salary) from employee)
union
select Empname, salary from employee
where salary = (select max(salary) from employee);
Task 11: Write a query to display the employee id, employee name, jobname of all the
employees whose salary is greater than 90,000 P.A.
select employee_id,Empname, jobname from employee where
Salary>90000;
Document Page
6
DATABASE MODELLING
Task 12: write a query to display the all the details of all the employees whose jobname is
Manager.
select * from employee where jobname='Manager';
Task 13: Write a query to display the all the details of the employee whose name is Robert.
select * from employee where Empname='Robert';
Task 14: Write a query to display all the details of the employee who work as a manager and
have salary greater than 95000 P.A.
select * from employee where jobname='Manager' and Salary>95000;
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
7
DATABASE MODELLING
Task 15: Write a query to display employeeid, employee name, jobname and date of joining
of all the employees who joined after year 2001.
select employee_id,Empname, jobname, Dateofhire from employee where
year(Dateofhire)>2001;
Task 16: Write a query to display the list of all the employees whose annual salary is within
the range 55000 and 95000.
SELECT * from employee where Salary>55000 and Salary<95000;
Task 17: Write a query to display the list of all the employees in the descending order of
their salaries.
select * from employee ORDER by Salary desc;
Document Page
8
DATABASE MODELLING
Task 18: Write a query to count the number of employees in the employee table.
select count(*) as TotalEmployees from employee;
Task 19: Insert a new record in the employee table and add ANALYST as their jobname.
INSERT INTO employee values (1012, 'Lily', 5091, '2020-01-15',
'ANALYST', '76500.00', 2012, '1995-11-08', 'Hobart');
Task 20: Insert a new record in the employee table with the following data fields
employee_id= 1011 empname= Janet jobname= PROGRAMMER managerid= 5095
dateofhire= 12-10-2014 salary= 90000 department_id=2011.
INSERT INTO employee values (1011, 'Janet', 5095, '2014-10-12',
'PROGRAMMER', '90000.00', 2011, '1995-11-26', 'Sydney');
Document Page
9
DATABASE MODELLING
Task 21: Write a query to delete the record of the employee whose name is ‘Flynn’.
delete from employee WHERE Empname='Flynn';
Task 22: Write a query to update the salary by 15% of the employee whose employee name
is ROBERT.
update employee
set salary = (Salary*(15/100)+Salary)
where Empname='Robert';
Task 23: Write a query to find the number of staff working in each department and the sum
of their salaries.
select d.deptname, count(e.employee_id) as `no of staffs`,
sum(e.salary) as sum from department d, employee e where
e.Department_id=d.Department_id GROUP by (d.Deptname);
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
10
DATABASE MODELLING
Task 24: Write a query to find all employees with the string ‘Avenue’ in their address.
select * from employee where Address like '%Avenue%';
chevron_up_icon
1 out of 11
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]