You are on page 1of 10

Database programming evaluation practical

Task 1:

Creating Department Table

Create table function is used to create the table. Based on the table the Column name and the data
type are entered.

Since Department_id is the primary key we had to create the Department Table before creating the
employee table

CREATE TABLE DEPARTMENT


(department_id INT PRIMARY KEY,
Deptname VARCHAR (30) NOT NULL,
deptLocation VARCHAR (20) NOT NULL,
deptFloor VARCHAR (20) NOT NULL);

Creating Salary Table

Create table function is used to create the table. Based on the table the Column name and the data
type are entered.

CREATE TABLE SALARY


(salary_level INT PRIMARY KEY,
salarymin INTEGER NOT NULL,
salarymax INTEGER NOT NULL);

Creating Employee Table

Create table function is used to create the table. Based on the table the Column name and the data
type are entered.

CREATE TABLE EMPLOYEE ( employee_id INT PRIMARY KEY,


Empname VARCHAR(25) NOT NULL,
Managerid INTEGER NOT NULL,
Dateofhire DATE NOT NULL,
Jobname VARCHAR(15) NOT NULL,
Salary DECIMAL (10,2) NOT NULL,
department_id INT NOT NULL,
DOB DATE NOT NULL,
Address VARCHAR(30) NOT NULL,
FOREIGN KEY (department_id)
REFERENCES DEPARTMENT)

Task 2:

To enter values into the table we use the Insert Into function. We can either make the entries one by
one or all 10 at a time. I have entered all 10 records in a single command.

If we are entering all the fields of the row we can skip giving the column names before the values.

INSERT INTO employee (employee_id, Empname, Managerid, Dateofhire, Jobname, Salary,


Department_id, DOB, Address)
VALUES
('1001', 'Maria', '21', '2000-06-04', 'Programmer', '95000', '2011', '1985-05-26',
'Dock Avenue, Perth'),
('1002', 'Anders', '21', '2000-10-10', 'Programmer', '85000', '2011', '1988-08-31',
'31 Avenue , TAS'),
('1003', 'Ana', '21', '2010-08-13', 'Programmer', '95000', '2011', '1990-02-11',
'Bakers Avenue, Sydney'),
('1004', 'Antonio', '23', '2012-08-24', 'Tester', '60000', '2014', '1983-09-22',
'Barkly Street, Perth'),
('1005', 'Thomas', '23', '2015-05-02', 'Tester', '70000', '2014', '1991-05-10',
'Bakers Avenue, Melbourne'),
('1006', 'Hardy', '23', '2016-02-11', 'Tester', '50000', '2014', '1991-08-25',
'Commercial Road, Perth'),
('1007', 'Christina', '22', '2016-08-27', 'HR', '80000', '2015', '1993-06-27', 'White
Street, Perth'),
('1008', 'Bernard', '24', '2019-04-12', 'Analyst', '100000', '2012', '1994-03-08',
'Hallmark Centre, Perth'),
('1009', 'Finch', '25', '1996-07-05', 'Manager', '120000', '2013', '1980-03-29',
'Green Road, Perth'),
('1010', 'Jason', '25', '1998-08-27', 'Manager', '100000', '2013', '1982-04-11', '10
Downing Street, Perth');

Task 3

To enter values into the table we use the Insert Into function. We can either make the entries one by
one or all 5 at a time. I have entered all 5 records in a single command. I have skipped giving the
column names as I am entering all the corresponding data.

Department Data was entered before the data in the employee because of the dependency in the
primary and foreign key.

Insert Into DEPARTMENT


Values
('2011','Development','Perth','20'),
('2012','Analyst','Perth','21'),
('2013','Management','Perth','22'),
('2014','Tester','Perth','20'),
('2015','HR','Perth','23');

Task 4

To enter values into the table we use the Insert Into function. We can either make the entries one by
one or all 5 at a time. I have entered all 5 records in a single command.
Insert Into SALARY(Salary_level, Salarymin, Salarymax)
Values
('1','40000','60000'),
('2','60000','80000'),
('3','80000','100000'),
('4','100000','120000'),
('5','120000','150000');

Task 5: Write a query to display the information about the employees in the employee
Table

As we need to display all the data of the employees I have used “*” which gives us all the rows in the
table Employee.

Select * from Employee

Task 6

I have used the SELECT command with the column name to display the data under the specific
column name.

Select Empname from EMPLOYEE

Task 7

I have used the SELECT command with the column names to display the data under the specific
column name. We have selected Empname and Jobname fields to be displayed the Employees table.

Select Empname, Jobname from EMPLOYEE


Task 8

As the requirement was to show unique job names under the column Jobname I have used the
Select Distinct Function on the Employee table.

Select Distinct Jobname from EMPLOYEE

Task 9

We had to increase the salary data by 12%. To do the same I have used the Update command.
To display the fields I have used the select command with the column names Empname, Jobname
and Salary to show the increased salaries.

Update EMPLOYEE
Set Salary=Salary * 1.12

Select Empname, Jobname , Salary from EMPLOYEE

Task 10
To display the name of the employees who have the minimum and maximum salary we use the
Select function with the Where condition. To know the Minimum and Maximum salary we need to
use the Min() and Max() function.

Select empname
From employee
Where salary in((select min(salary) from employee),(select max(salary) from employee)
);

Task 11

To display the Employee id, empname and jobname who have the salary greater than 90000 we use
the select function with the Which condition.

SELECT employee_id, empname, jobname, salary


FROM employee
WHERE salary>=90000;

Task 12

To display all the data of the employees who are managers we use the select function with the
Where condition.

SELECT *
FROM employee
WHERE Jobname='manager';

Task 13

To display all the data of the employees who are managers we use the select function with the
Where condition with empname is robert.
SELECT *
FROM employee
WHERE Empname='Robert';

Task 14

To display all the data of the employees who are managers and salary greater than 95000 we use the
select function with the Where condition with 2 conditions.

SELECT *
FROM employee
WHERE Jobname='manager' AND Salary>=95000

Task 15

To display the employee id, employee name, Job name and date of hire who joined after 2001 we
use the WHERE condition and the YEAR function on the Date of hire.

SELECT employee_id ,Empname, Jobname, Dateofhire


FROM employee
WHERE Year(Dateofhire)>=2001-01-01;

Task 16

To display all the data of the employees who salary greater than 55000 and less then 95000 we use
the select function with the Where condition with 2 conditions.

SELECT *
FROM employee
WHERE Salary<=95000 and Salary>=55000;
Task 17

To display details in an order we use the Order By condition on the Employee table

SELECT *
FROM employee
order by Salary Desc;

Task 18
To give the count of the details we have to use the Count Function on the Employee_id

SELECT Count(employee_id) As 'Number of employees'


FROM employee;

Task 19
I have used the Insert into function to enter the details of an employee.

INSERT INTO employee VALUES


('1012', 'Flynn', '1010', '2017-03-02', 'Analyst', '100000', '2012', '1987-06-06',
'Woodridge,Perth');

Task 20
I have used the Insert into function to enter the details of an employee. As the data is incomplete I
had to enter the column names.

INSERT INTO employee (employee_id, Empname, Managerid, Dateofhire, Jobname, Salary,


Department_id, DOB, Address)
VALUES
('1011', 'janet', '5095', '2014-10-12', 'PROGRAMMER', '90000', '2011', '', '');
Task 21

To delete the row with the employee name Flynn we used the Delete function with the Where
condition.

DELETE FROM employee


WHERE empname='Flynn';

Task 22
To increase the salary of one particular employee we can use the Update function with a Where
condition.

Update EMPLOYEE
Set Salary=Salary + (Salary * 15)/100
Where Empname='Robert';

Task 23
To display the sum of the salaries of the employees who are there in the same department we use
Count() and Sum() functions along with Group By function on the department ID

SELECT department_id, COUNT(*) As Employees_Count,SUM(salary) AS Total_Salary FROM


employee GROUP BY department_id;
Task 24

To Display the details of the employees who have the string ‘avenue’ in there address we
need to use the Where condition with the LIKE function. As the string can be in position in
the address we use % to search the string.

Select * from EMPLOYEE WHERE Address like '%Avenue%';

You might also like