Sei sulla pagina 1di 17

1. ANS.

a)

Create your own database.

b)

Create table within it with the following fields giving name as Employee table. (Empno, empname, Job, Salary, Deptno.)

ANS. ) create table employee( empno integer, empname varchar2(30), job varchar2(30), salary number(10,2), deptno integer); c) Ans.) insert into employee values(1,'RAKESH','ENGINEER',15000.00,11); insert into employee values(2,'PAWAN','ENGINEER',15000.50,12); insert into employee values(3,'VISHAL','Sr.ENGINEER',25000.00,13); insert into employee values(4,'SUHAS','ANALYST',16000.00,14); insert into employee values(5,'UMESH','Sr.ANALYST',22000.00,15); d) Ans.) select * from employee; output
44170288286817 21606912080381 14144690751258 5 44183034646933 21736625668766 select * from emp 21572909937200 14106352553967

Insert five records in above created table.

Verify by displaying data by select statement.

EMPNO 2 5 1 3

EMPNAM E PAWAN UMESH RAKESH VISHAL

JOB ENGINEER Sr.ANALYST ENGINEER Sr.ENGINEER

S AL ARY 15000.5 22000 15000 25000

DEPTNO 12 15 11 13

SUHAS

ANALYST

16000

14

2.Use Employee table : a) ANS> select * from employee where deptno=11; output:
EMPNO 1 EMPNAM E RAKESH JOB ENGINEER S AL ARY 15000 DEPTNO 11

Display records of a selected deptno.

b) Ans>

Display the record of selected person.

select * from employee where empname='VISHAL'; output:


EMPNO 3 EMPNAME VISHAL JOB Sr.ENGINEER SALARY 25000 DEPTNO 13

c) ANs>

Display the record of selected Job.

select * from employee where job='ENGINEER';


Output:
44170288286817 1 44183034646933 21736625668766 select * from emp 21572909937200

21606912080381 14144690751258

14106352553967

EMPNO 2

EMPNAME PAWAN

JOB ENGINEER

SALARY 15000.5

DEPTNO 12

RAKESH

ENGINEER

15000

11

d)

Display the records of given selected salary range. Ans> select * from employee where salary between 15000 and 22000; output:

EMPNO 2 5 1 4

EMPNAME PAWAN UMESH RAKESH SUHAS

JOB ENGINEER Sr.ANALYST ENGINEER ANALYST

SALARY 15000.5 22000 15000 16000

DEPTNO 12 15 11 14

e)

Display only the selected columns.

Ans.> select empno,job,deptno from employee ; output:

EMPNO 2 5 1 3 4

JOB ENGINEER Sr.ANALYST ENGINEER Sr.ENGINEER ANALYST

DEPTNO 12 15 11 13 14

f)

Display by adding some title to the column Ans.> select empno,empname,salary,job,PHONE_NO as DOJ from employee; Output:

3. Use Employee table : a)Add one more column to table i.e. Phone_no. ans> alter table employee add(phone_no date); output:
EMPNO 2 5 1 3 4 EMPNAME PAWAN UMESH RAKESH VISHAL SUHAS JOB ENGINEER Sr.ANALYST ENGINEER Sr.ENGINEER ANALYST SALARY 15000.5 22000 15000 25000 16000 DEPTNO 12 15 11 13 14 PHONE_NO -

b)Modify the Employee name column by changing the data length ans> alter table employee modify(empname varchar2(50)); c)Make the empno. as primary key.

ANS> alter table employee modify(empno primary key); d)Insert date in phone field of each each employee by selecting him with empno. ANS> update employee set phone_no='11/30/2011' where empno=1; update employee set phone_no='12/30/2011' where empno=2; update employee set phone_no='01/30/2012' where empno=3; update employee set phone_no='02/28/2011' where empno=4; update employee set phone_no='03/30/2011' where empno=5; output:

4.a)Create another table dept with three column: deptno, dname and Location with deptno was primary key. Insert records in it keeping in view deptno in employee table.

create table deprt( deptno number(10)primary key, dname varchar2(30), location varchar2(30)); insert into deprt values (11,'sales','noida');

insert into deprt values (12,'hr','delhi'); insert into deprt values (13,'computer','meerut'); select * from deprt; output:

b)Create the relation between employee table and Dept table on the basis of deptno that mean deptno in the employee will be as foreign key in that table. ANS> ALTER TABLE employee ADD FOREIGN KEY (deptno) REFERENCES deprt(deptno); c) Display the available records in dept table. ANS> select * from deprt;

5.a)Insert some more record in employee table and verify the effects of constraints applied in adding deptno. ANS> insert into employee values(6,'ROHAN','ANALYST',16000,14,'03/30,2012');

This will produce error because after applying foreign key in employee table for dept no which is a primary key in deprt table,it doesnt allow any modification. So we have to add the deptno=14 entry in deprt table so that we can easily add data in employee table. SO ouput after adding depno=14 in deprt table : insert into deprt values (14,'finance','meerut'); insert into employee values(6,'ROHAN','ANALYST',16000,14,'03/30,2012'); insert into employee values(7,'RASHI','ANALYST',16000,14,'04/30,2012'); EMPLOYEE TABLE

DEPRT TABLE:

b)Update records of some employee by transferring them from one dept to another. ANS> BEFORE UPDATION EMPLOYEE TABLE AS:

AFTER UPDATION EMPLOYEE TABLE AS: update employee set deptno=13 where empno=6; update employee set deptno=14 where empno=4;

c)Update the salary of some employees (give 10% increase) on dept basis in employee table. ANS> BEFORE UPDATION EMPLOYEE TABLE AS:

AFTER UPDATION EMPLOYEE TABLE AS: update employee set salary=(salary+10/100*salary) where deptno=11; update employee set salary=(salary+10/100*salary) where deptno=14;

d)Delete some record from employee table and verify the output using select. ANS>delete from employee where empno=7; delete from employee where empno=5;

output:

6.a)Count the total no of employee. ANS> select count(empno) from employee;

To count all rows command as follows: select count(*) from employee;

b)Count the sum of salary using employee table. ANS> select sum(salary)from employee; output:

c)Calculate the avg salary of employee. ANS> select avg(salary)from employee;

d)Determine the max and min salary of employees. ANS> select max(salary)from employee;

select min(salary)from employee;

7.a)Count the no of employees deptt wise using Group by & having clauses. ANS> select deptno,count(deptno)from employee group by deptno having count(deptno)>0;

Output:

44170288286817

44183034646933 21736625668766

select deptno,cou 21572909937200 14106352553967

21606912080381 14144690751258

DEPTNO 11 13 14 12

COUNT(DEPTNO) 2 1 1 1

b)Display the some of salaries deptt wise. ANS> select deptno,sum(salary)from employee group by deptno; OUTPUT:

DEPTNO 11 13 14 12

SUM(SALARY) 33000.55 16000 17600 25000


44170288286817 21572909937200 21736625668766 14144690751258 4 44183034646933 21606912080381 14106352553967 select deptno,sum

c)Display avg salary deptt wise. ANS> select deptno,avg(salary)from employee group by deptno; output:
DEPTNO 11 13 14 12 AVG(SALARY) 16500.275 16000 17600 25000

d)Display max and min salary deptt. wise. ANS> select deptno,max(salary)from employee group by deptno;
DEPTNO 11 13 14 12 MAX(SALARY) 16500.55 16000 17600 25000

select deptno,min(salary)from employee group by deptno;


DEPTNO MIN(SALARY)

11 13 14 12

16500 16000 17600 25000

8.a)Display emp_no and emp name from employee table alongwith deptt. namefrom dept table. ANS> select empno,empname,dname from employee,deprt where employee.deptno= deprt.deptno;

OUTPUT:
EMPNO 2 1 3 4 6 EMPNAME PAWAN RAKESH VISHAL SUHAS ROHAN DNAME sales sales hr finance computer

b)Count employee of employee table by giving department name. ANS> select count(empno) from employee,deprt where deprt.dname='sales' AND deprt.deptno=employee.deptno; output:
COUNT(EMPNO) 2

c)Display some more lists by using join statement.

ANS> select empno,empname,job,dname,location from employee,deprt where employee.deptno= deprt.deptno;

9.a)Create table by using sub query statement. Display the records. ANS> create table temp as select * from employee; select * from temp; output : TEMP TABLE AS: {//to display temp table data}

b)Create table with selected column by using sub queries. Display the output to see data. ANS>

create table tempcol as select empno,empname,salary from employee; select * from tempcol; {//to display tempcol table data}

output:

10.a)Create view using single table with selected columns. ANS> create view v as select empno,empname,job from employee; select * from v; OUTPUT: {//to display view v data}

b)Create view using multiple tables using selected columns. ANS> create view vm as select empno,empname,job,dname,location from employee,deprt where employee.deptno= deprt.deptno;

select *from vm;

{//to display view vm data}

OUTPUT:

11.a)Delete selected records from table by using some conditions. ANS> delete from employee where salary between 16000 and 17000; select *from employee; OUTPT:

b)Drop column from table. ANS> ALTER TABLE employee DROP COLUMN salary; select *from employee; OUTPUT:

c)Truncate table. ANS> truncate table employee; select count(*) from employee; OUTPUT:

d)Drop table. ANS> drop table employee; drop table deprt;

Potrebbero piacerti anche