Anda di halaman 1dari 3

1.

Write SQL statements to create the above two tables DEPARTMENT and EMPLOYEE using CREATE

table statement.

Create table department


(dept no char (5),
Deptname varchar (35),
mgrno char (10),
admrdept char (5),
location char (10),
);

Create table employee


(empno char (10),
Firstname varchar(15),
Lastname varchar (20),
Workdept char (5),
Phoneno char (5),
Job char (10),
Sex char (5),
Salary decimal (10,2),
Bonus decimal (10,2),
Comm decimal (10,2)
);

2. Find all the employees from employee table.


Select * from employee;

3. Find all the employees from employee table who are female.

Select * from employee


Where sex = ‘F’;

4. Find all the manager number from the department table in descending order of manager number.

Select MGRNO from department


Order by mgrno DESC;

5. Find all the department names from department table in ascending order of department number.

Select Deptname from department


Order by deptname;
6. Find the employee number, last name, phone number and salary of each employee from

employee table.

Select EMPno, lastname, phoneno, salary from employee;

7. Find the employee number, last name, salary and an increment of 10% salary renaming the

heading as “Increment” from the employee table and sort them according to the increment in

descending order.

Select empno, lastname, salary, salary*1.1 as “Increment”


from employee order by increment DESC;

8. Find those employees from employee table who are clerk and earn salary more than 20000.

Select* from employee


Where salary>20000 and job = ‘CLERK’;

9. Insert a new record to the employee table which contains “BRIAN” as last name, 000350 as

employee number, 25000 as salary, “OPERATOR” as job.

Insert into employee


(lastname,empno, salary, job)
Values(‘BRIAN’, ‘000350’,25000,’OPERATOR’);

10. Insert a new record to the employee table which contains “SHING” as last name, 000360 as

employee number, 25000 as salary, “CLERK” as job, and female as sex.

Insert into employee


(lastname, empno, salary, Job, sex)
Values(‘SHING’, ‘000360,25000,’CLERK’, ‘F’);

11. Delete all the records from department table.

Delete from Department;


12. Delete all the records from employee table who are clerk.

Delete from employee


Where job=’CLERK’;

13. Delete all the records from employee table that are operator and earn salary less than 17000.

Delete from employee


Where job = ‘OPERATOR’ and salary<1700;

14. Increase the salary of all employees in employee table by 8% of existing salary.

Update employee
Set salary =salary*1.08;

15. Change the work department of employee number 000250 from D21 to F21 in employee table.

Update employee
Set workdept = ‘F21’
Where empno = ‘000250’;

16. Find the phone number of the employee name DANIEL in employee table.

Select phoneno from employee where firstname = ‘DANIEL’;

Anda mungkin juga menyukai