You are on page 1of 6

lOMoARcPSD|273 440 80

1. A college consists of number of employees working in different departments. In this context,


create two tables’ employee and department. Employee consists of columns empno, empname,
basic, hra, da, deductions, gross, net, date-of-birth. The calculation of hra,da are as per the rules
of the college. Initially only empno, empname, basic have valid values. Other values are to be
computed and updated later. Department contains deptno, deptname, and description columns.
Deptno is the primary key in department table and referential integrity constraint exists between
employee and department tables. Perform the following operations on the database:
1. Create tables department and employee with required constraints.
2. Initially only the few columns (essential) are to be added. Add the remaining columns
separately by using appropriate SQL command
3. Basic column should not be null
4. Add constraint that basic should not be less than 5000.
5. Calculate hra,da,gross and net by using PL/SQL program.
6. The percentage of hra and da are to be stored separately
7. When the da becomes more than 100%, a message has to be generated and with user
permission da has to be merged with basic.
8. Empno should be unique and has to be generated automatically.

1. Create tables department and employee with required


constraints. QUERY:
create table emp (empno number(10) primary key, ename varchar2(10), basic number,
hra number, da number, deductions number, gross number, net number, deptno number
references dept(deptno));

OUTPUT:
Table Created

QUERY:

Create table dept( deptno number primary key, dname varchar2(20), description varchar2(40));
lOMoARcPSD|273 440 80

OUTPUT:
Table Created

2. Initially only the few columns (essential) are to be added. Add the remaining columns
separately by using appropriate SQL command
QUERY
Alter table emp add (dob date,doj date);

OUTPUT:
Table Altered

3. Basic column should not be


null QUERY:

alter table emp modify basic number(10) not null ;


OUTPUT:
Table Altered

4. Add constraint that basic should not be less than


lOMoARcPSD|273 440 80

5000. QUERY:

alter table emp add constraint emp_chkl check(basic>5000);

OUTPUT:
Table Altered

5. Insert atleast 5 records in both the tables

QUERY:

Insert into dept (deptno, dname, description) values ('&deptnp','&dname','&description');

OUTPUT:

QUERY:

insert into emp (empno,ename,basic,hra,da,deductions,gross,net,deptno,dob,doj) values


(&empno,'&ename',&basic,&hra,&da,&deductions,&gross,&net,&deptno,'&dob','&doj') ;

OUTPUT:
lOMoARcPSD|273 440 80

6. Calculate hra,da, gross and net by using PL/SQL program.

PL/SQL PROGRAM

Declare
Cursor e is select * from emp;
Begin
Update emp set hra= basic * 0.5, da= basic * 0.1, deductions= basic * 0.15, gross= basic + hra +
da, net= gross - deductions;
end;
OUTPUT:
pl/sql procedure successfully completed

7. The percentage of hra and da are to be stored


separately QUERY:
lOMoARcPSD|273 440 80

alter table emp add hrap number(5,2);


OUTPUT:
Table Altered

QUERY:
alter table emp add dap number(5,2);
OUTPUT:
Table Altered

8. When the da becomes more than 100%, a message has to be generated and with user
permission da has to be merged with basic.
PL/SQL PROGRAM

Create or replace trigger da1


Before insert or update on emp for each row
begin
if :new.da>bsal then
raise_application_error (-20456,'the da is not accepted, so the da is merge to basic’);
end if;
end;
OUTPUT:
Trigger Created Successfully.

9. Empno should be unique and has to be generated


automatically.

QUERY:
Create or replace sequence
s1 Increment by 1
Start with 501
lOMoARcPSD|273 440 80

End with 590


No cache
No cycle;
Insert into employee values (s1.nextval,’siva’, 9000, 900, 4500);
Insert into employee values (s1.nextval,’siva’, 9000, 900, 4500);

OUTPUT:
Sequence created.
10. Display all the records in both the tables.

QUERY:

Select * from emp;

OUTPUT:

QUERY:

Select * from dept;

OUTPUT:

You might also like