Sunteți pe pagina 1din 62

EX NO:

DATE:

QUESTION:

a.Which parameters should the backup copygroup have, to keep only the last backup copy of data
indefinitely after the file has been deleted from the file system and a daily incremental backup has
been completed?
b. Which parameters should the copygroup have, to retain four inactive versions of a file
when the file is available on client system?
c. Which statement described a device class?
d. which type of storage pool can use either a sequential access device class or a random
access device class?
e. Given that active-data pools contain only active versions of client data, which statement is true
about the use of active-data pools?


AIM:

To create a report for IBM Tivoli.

ANSWER:

a.Which parameters should the backup copygroup have, to keep only the last backup copy of data
indefinitely after the file has been deleted from the file system and a daily incremental backup has
been completed?
Ans: NOLIMIT
b. Which parameters should the copygroup have, to retain four inactive versions of a file when
the file is available on client system?
Ans: Set the Versions Data Exists parameter (verexists=5)

c. Which statement described a device class?
Ans: To define a device class, use the DEFINE DEVCLASS command and specify the
DEVTYPE parameter. The DEVTYPE parameter assigns a device type to the
device class.
d. which type of storage pool can use either a sequential access device class or a random
access device class?
Ans: Random access storage pool
e. Given that active-data pools contain only active versions of client data, which statement is true
about the use of active-data pools?
Its not possible to say whether it is true or false.
RESULT:
Thus the report was created about the Tivoli.


EX NO:
DATE:

QUESTION:

Religion is a special form of the world view, which is based on the faith in the
supernatural powers, and includes a set of moral values and types of behavior, rituals and
gathering of people into the organizations (a church, a religious community, etc.). People
have always believed that some supernatural powers and creatures created the world, and all
the people, animals, birds and the objects of nature are the results of their creation. Every
religion is based on the opposition of the real world or the world of the live and the world
which waits people after their death. The explanation of this opposition is very simple,
because the world people live in is full of evil, stress and difficulties and people have always
wanted to escape into the better world and religion gives them such a possibility claiming that after
death everyone will have a better life.
Some religions do not promise a better life but just say that the life will be different from the
present one. There are five key religions in the world which gather an enormous number of
adherents: Christianity, Islam, Hinduism, Chinese folk religion and Buddhism. Religion is quite an
controversial topic for discussion, because a great number of people do not accept any type of
religion claiming that every religious organization is simply an excellent way to earn money, rule
people and hide the truth from them. No wonder, on the basis of religion
there always have been military conflicts, violence and crimes. In order to reduce the number of
such incidents religion does not play any role in the political activity of the countries and every
person is free to choose any religion she wants.
In order to research the topic on religion a student should improve his knowledge on the
whole topic. A good religion case study is expected to be informative, interesting and contain only
up-to-date facts which help to cope with the process of research. A student should
collect enough information to study the case site and understand the cause of the problem which
has occurred in the case. After that he is obliged to analyze the effect of the problem and
brainstorm the best effective solutions to the problem based on religion.
For the above business stories you are expected to create the following
1. Analyze the data required.
2. 2. Normalize the attributes.
3. 3. Create the logical data model (ER diagrams).





AIM:
To execute a query for to create a database for a religion.
DESCRIPTION:
To create a database for university. Under university we have a several branches.
Each branch have a several attributes. For this, I have used four techniques.they are,
(i)create table.
(ii)insert
(iii)alter
(iv)primary key and foreign key.
SYNTAX:
Create table tablename(fields name);
Insert into tablename values(fields values);
Alter table tablename(fields);
QUERY:
OUERY1:
create table hindu(hindu_name varchar(8),h_no number(3),hindu_city varchar(8),h_pop
varchar(4),h_educated varchar(8),h_gender varchar(7));
QUERY2:
insert into hindu values('priya',1,'namakkal',1000,'educated','female');
insert into hindu values('jegan',1,'namakkal',1000,'educated','male');
insert into hindu values('vadivu',4,'namakkal',1500,'educated','female');
insert into hindu values('mani',3,'namakkal',3000,'uneducat','male');
QUERY3:
create table muslims(m_name varchar(8),m_no number(2),m_city varchar(8),m_pop
number(4),m_educated varchar(8),m_gender varchar(6));
QUERY4:
insert into muslims values('jaya',5,'covai',1500,'educated','female');
insert into muslims values('yogith',6,'covai',1200,'educated','male');


insert into muslims values('rani',6,'namakkal',1200,'uneducat','female');
QUERY5:
create table christians(c_name varchar(5),c_no number(2),c_city varchar(6),c_educated
varchar(7),c_gender varchar(6));
QUERY6:
insert into christians values('pri',2,'trichi','educat','female');
insert into christians values('bhuvi',7,'trichi','educat','female');
insert into christians values('hari',7,'trichi','unedu','male');

T a b l e C o l u m n D a t a T y p e L e n g t h P r e c i s i o n S c a l e P r i m a r y K e y N u l l a b l e D e fa u l t C o m m e n t
HINDU HINDU _NAME Varchar2 8 - - - - -
H _NO Number - 3 0 - - -
HINDU _CITY Varchar2 8 - - - - -
H _POP Varchar2 4 - - - - -
H _EDUCATED Varchar2 8 - - - - -
H _GENDER Varchar2 7 - - - - -
1 - 6


Select *from hindu;

HINDU _NAME H _NO HINDU _CITY H _POP H _EDUCATED H _GENDER
priya 1 namakkal 1000 educated female
jegan 1 namakkal 1000 educated male
vadivu 4 namakkal 1500 educated female
mani 3 namakkal 3000 uneducat male


select *from muslims;

M _ N A M E M _ N O M _ C I T Y M _ P O P M _ E D U C A T E D M _ G E N D E R
jaya 5 covai 1500 educated female
yogith 6 covai 1200 educated male
rani 6 namakkal 1200 uneducat female

select *from christians;

C _ N A M E C _ N O C _ C I T Y C _ E D U C A T E D C _ G E N D E R
p ri 2 tric h i e d u c a t fe m a le
b h u v i 7 tric h i e d u c a t fe m a le
h a ri 7 tric h i u n e d u m a le


RESULT:
Thus the sql queries are executed for the religion database.


EX NO:
DATE:

QUESTION:

Create an ER diagram that models the relationships in the system



play
away


Players
playin
Teams Games








play
away




ban attend











Banned Referees
Referees








are from





QUERIES;
QUERY1:
Create table game(game_name varchar(20) primary key);
Table created.
Desc game;

Tab Colum Data Len Precis Sca Primary Nulla Defa Comm
le n Type gth ion le Key ble ult ent
GAM GAME_N
E AME

Varchar2 20 - -

1 - - -

create table team1(team_name varchar(20) primary key,player_name
varchar(20),game_name varchar(20) references game(game_name));
Table created.
Desc team1;

Tab Data Len Precis Sca Primary Nulla Defa Comm
le Column Type gth ion le Key ble ult ent

TEA TEAM_NA
M1 ME


Varchar2 20 - -


1 - - -

PLAYER_
NAME


Varchar2 20 - - - - -

GAME_NA
ME
Varchar2 20 - - - - -



create table referee1(game_name varchar(20)references game,ref_name varchar(20),ref_id
number(10) primary key,ref_age number(10));
desc referee1;

Tabl Colum Data Len Precis Sca Primary Nulla Defa Comm
e n Type gth ion le Key ble ult ent

REFER GAME_N
EE1 AME


Varchar2 20 - - - - -

REF_NA
ME
Varchar2 20 - - - - -

REF_ID Number - 10 0 1 - - -







REF_AG
E







Number - 10 0 - - -
create table player(game_name varchar(20) references game (game_name),player_name
varchar(20),pla_nr number);
desc player;

Tab Data Len Precis Sca Primary Nulla Defa Comm
le Column Type gth ion le Key ble ult ent

PLAY GAME_NA
ER ME


Varchar2 20 - - - - -

PLAYER_
NAME


Varchar2 20 - - - - -

PLA_NR Number - - - - - -

create table ban_ref(ref_id number references referee1(ref_id),ref_name varchar(20),ref_age
number);
desc ban_ref;

Tabl Colu Data Len Precis Sca Primary Nulla Defa Comm
e mn Type gth ion le Key ble ult ent

BAN_
REF
REF_ID Number - - - - - -

REF_N
AME


Varchar2 20 - - - - -

REF_A
GE


Number - - - - - -

create table referee(ref_name varchar(20),ref_age number,ref_id number primary key);
desc referee;

Tabl Colu Data Len Precis Sca Primary Nulla Defa Comm
e mn Type gth ion le Key ble ult ent

REFE REF_N
REE AME


Varchar2 20 - - - - -

REF_A
GE
Number - - - - - -

REF_ID Number - - - 1 - - -





QUERY2:
insert into game values('football');
insert into game values('bascketball');
select *from game;

GAME _NAME
Football
Bascketball
kabadi


insert into team1 values('killy','vijay','kabadi');
insert into team1 values('india','vijay','football');
insert into team1 values('pakisthan','jegan','bascketball');
select *from team1;

TEAM _NAME PLAYER _NAME GAME _NAME
killy Vijay kabadi
india Vijay football
pakisthan jegan bascketball
insert into referee1 values('football','john',213,33);
insert into referee1 values('bascketball','hari',218,39);
insert into referee1 values('kabadi','yogith',438,37); select
*from referee1;

GAME _NAME REF _NAME REF _ID REF _AGE
football John 213 33
bascketball Hari 218 39
kabadi Yogith 438 37
insert into player values('kabadi','mani',456);
insert into player values('football','archu',498);
insert into player values('bascketball','priya',654);
select *from player;

GAME _NAME PLAYER _NAME PLA _NR
kabadi mani 456
football archu 498







bascketball priya 654


insert into ban_ref values(213,'john',33);
1 row(s) inserted.
select *from ban_ref;

REF _ID REF _NAME REF _AGE
213 John 33


QUERY3: (INNER JOIN)
select game.game_name,team1.team_name,team1.player_name from game inner join team1
on game.game_name=team1.game_name;

GAME _NAME TEAM _NAME PLAYER _NAME
kabadi killy Vijay
football india Vijay
bascketball pakisthan Jegan


QUERY4: (RIGHT OUTER JOIN)
select ban_ref.ref_id,referee.ref_name,ban_ref.ref_age from referee right outer join ban_ref
on ban_ref.ref_id=referee.ref_id;

REF _ID REF _NAME REF _AGE
213 - 33


QUERY5: (LEFT OUTER JOIN)
select ban_ref.ref_id,referee.ref_name,ban_ref.ref_age from referee left outer join ban_ref on
ban_ref.ref_id=referee.ref_id;
no data found.
QUERY6: (CROSS JOIN)
select ban_ref.ref_id,referee.ref_name,ban_ref.ref_age from referee cross join ban_ref; no
data found.


QUERY7: (ORDERBY)
select ref_name,ref_id from referee1 order by ref_id;






REF _NAME REF _ID
John 213
Hari 218
Yogith 438
QUERY8: (WHERE)
select player_name from player where game_name='kabadi';

PLAYER _NAME
Mani
ER DIAGRAM:
ref_age
Team name game name






team

Ref_name




game

Ref_id





referees






Players Banned referees






Player name Player_id Ban_ref_age Ban_ref_id

Player age
Ban_ref_name






RESULT:
Thus the ER diagram was created with relationship models.



EX NO:
DATE:

QUESTION:

(i). To calculate the number of days left in a month.
(ii). How many days has each employee been in his or her current job?
AIM:
To create a queries for calculating date differences.
DESCRIPTION:
To create a database for university. Under university we have a several branches.
Each branch have a several attributes. For this, I have used four techniques.they are,
(i)create table.
(ii)insert
(iii)alter
(iv)primary key and foreign key.
SYNTAX:
Create table tablename(fields name);
Insert into tablename values(fields values);
Alter table tablename(fields);


QUERIES:
QUERY 1:
create table employee(emp_name varchar(20),emp_id number,join_date date);
Table created.
desc employee;


Table Column Data Type Length Precision Scale Primary Key Nullable Default Comment
EMPLOYEE EMP_NAME Varchar2 20 - - - - -
EMP_ID Number - - - - - -
JOIN_DATE Date 7 - - - - -


SELECT *FROM EMPLOYEE;


EMP _NAME EMP _ID JOIN _DATE
priyanga 123 12-JAN-14
jegan 345 20-JAN-14
jeyasudha 156 22-JUL-12
yogith 136 13-AUG-11
vadivu 139 15-MAY-10
sharmila 159 19-FEB-11
kumar 153 18-MAR-11
karthees 177 15-APR-12
QUERY2:
select (last_day(sysdate) - sysdate) as days_left from employee where emp_name='jegan';

DAYS _LEFT
8
QUERY3:
select emp_name,emp_id,sysdate - join_date as nr_of_day from employee;


EMP _NAME EMP _ID NR _OF _DAY
priyanga 123 12.244224537037037037037037037037037037
jegan 345 4.24422453703703703703703703703703703704
jeyasudha 156 551.244224537037037037037037037037037037
yogith 136 895.244224537037037037037037037037037037
vadivu 139 1350.24422453703703703703703703703703704
sharmila 159 1070.24422453703703703703703703703703704
kumar 153 1043.24422453703703703703703703703703704
karthees 177 649.244224537037037037037037037037037037
Select (sysdate)-(join_date) as nr_of_day from employee ;

NR _OF _DAY
11.8774305555555555555555555555555555556
3.87743055555555555555555555555555555556
QUERY4: (ORDER BY)





select * from employee ORDER BY join_date;


EMP _NAME EMP _ID JOIN _DATE
Vadivu 139 15-MAY-10
Sharmila 159 19-FEB-11
Kumar 153 18-MAR-11
Yogith 136 13-AUG-11
Karthees 177 15-APR-12
Jeyasudha 156 22-JUL-12
Priyanga 123 12-JAN-14
Jegan 345 20-JAN-14



select upper(emp_name),emp_id from employee order by emp_id;


UPPER (EMP _NAME ) EMP _ID
PRIYANGA 123
YOGITH 136
VADIVU 139
KUMAR 153
JEYASUDHA 156
SHARMILA 159
KARTHEES 177
JEGAN 345
QUERY5: (BETWEEN)
select * from employee where join_date between '18-mar-2012' and '22-apr-2013';


EMP _NAME EMP _ID JOIN _DATE
jeyasudha 156 22-JUL-12
karthees 177 15-APR-12
OUERY6: (LIKE)
select * from employee where emp_name like '_a%';


EMP _NAME EMP _ID JOIN _DATE
vadivu 139 15-MAY-10
karthees 177 15-APR-12





RESULT:
Thus thequery was returned to calculate the date difference.


EX NO:
DATE:

QUESTION:

1) Display name,salary,hra,pf,da,total salary for each employee. The
output should be in the order of total salary,hra 15% of salary,da 10% of
salary,pf 5% salary,total salary will be(salary+hra+da)-pf.
2) Display depart numbers and total number of employees working in each
department.
3) Display the various jobs and total number of employees within each job
group.
4) Display the depart numbers and total salary for each department.
5) Display the depart numbers and max salary for each department.
6) Display the various jobs and total salary for each job
7) Display the various jobs and total salary for each job
8) Display the depart numbers with more than three employees in each dept.
9) Display the various jobs along with total salary for each of the jobs
where total salary is greater than 40000.
10) Display the various jobs along with total number of employees in each
job.The output should contain only those jobs with more than three employees.
AIM:
To create a queries for calculating the salary information.
DESCRIPTION:
To create a database for university. Under university we have a several branches.
Each branch have a several attributes. For this, I have used four techniques.they are,
(i)create table.
(ii)insert
(iii)alter
(iv)primary key and foreign key.
SYNTAX:
Create table tablename(fields name);
Insert into tablename values(fields values);
Alter table tablename(fields);





QUERIES:
create table employees(EMPLOYEE_ID number(10),FIRST_NAME
varchar2(20),LAST_NAME varchar2(20),EMAIL varchar2(20),PHONE_NUMBER
varchar2(30),HIRE_DATE date,JOB_ID varchar2(20),HRA number(20),PF number(20),DA
number(20),SALARY number(20),COMMISSION_PCT number(10),MANAGER_ID
number(10),DEPARTMENT_ID number(10));
Table created.
1)
select concat(FIRST_NAME,LAST_NAME)as NAME,SALARY,(15/100)*SALARY as
HRA,(10/100)*SALARY as DA,(5/100)*SALARY as
PF,(SALARY+((15/100)*SALARY)+((10/100)*SALARY))-((5/100)*SALARY) as
TOTAL_SALARY from employees;

NAME SALARY HRA DA PF TOTAL _SALARY
stevenking 24000 3600 2400 1200 28800
Neenakochhar 17000 2550 1700 850 20400
LexDehaan 17000 2550 1700 850 20400
AlexanderHunold 9000 1350 900 450 10800
BruceErnst 6000 900 600 300 7200
DianaLorentz 4200 630 420 210 5040
KebinMourgos 5800 870 580 290 6960
TrennaRajs 3500 525 350 175 4200
CurtisDavies 3100 465 310 155 3720
RandallMatos 2600 390 260 130 3120
PeterVargas 2500 375 250 125 3000
EleniZlotkey 10500 1575 1050 525 12600
EllenAbel 11000 1650 1100 550 13200
JonathonTaylor 8600 1290 860 430 10320
KimberelyGrant 7000 1050 700 350 8400
JenniferWhalen 4400 660 440 220 5280
MichaelHartstein 13000 1950 1300 650 15600
PatFay 6000 900 600 300 7200
ShelieyHiggins 12000 1800 1200 600 14400
WilliamGietz 8300 1245 830 415 9960

2)
select department_id,count(employee_id) from employees group by department_id;

DEPARTMENT _ID COUNT (EMPLOYEE _ID )
- 1
90 3
20 2
110 2
50 5
80 3







60 3
10 1


3)
select job_id,count(employee_id) from employees group by job_id;

JOB _ID COUNT (EMPLOYEE _ID )
IT_PROG 3
AC_MGR 1
AC_ACCOUNT 1
ST_MAN 1
AD_ASST 1
AD_VP 2
SA_MAN 1
MK_MAN 1
AD_PRES 1
SA_REP 3
MK_REP 1
ST_CLERK 4


4) select department_id,sum(salary) as total_salary from employees group by department_id;

DEPARTMENT _ID TOTAL _SALARY
- 7000
90 58000
20 19000
110 20300
50 17500
80 30100
60 19200
10 4400


5) select department_id,max(salary) from employees group by department_id;;

DEPARTMENT _ID MAX (SALARY )
- 7000
90 24000
20 13000
110 12000
50 5800
80 11000
60 9000
10 4400





6) select job_id,sum(salary) as TOTALSALARY from employees group by job_id;

JOB _ID TOTALSALARY
IT_PROG 19200
AC_MGR 12000
AC_ACCOUNT 8300
ST_MAN 5800
AD_ASST 4400
AD_VP 34000
SA_MAN 10500
MK_MAN 13000
AD_PRES 24000
SA_REP 26600
MK_REP 6000
ST_CLERK 11700


8) select department_id,count(employee_id)as COUNT from employees group by department_id
having count(employee_id)>3;

DEPARTMENT _ID COUNT
50 5

9)
select job_id,sum(salary) as TOTALSALARY from employees group by job_id HAVING
sum(salary)>40000;
no data found
10)
select job_id,sum(salary) as TOTALSALARY from employees group by job_id HAVING
sum(salary)>30000;

JOB _ID TOTALSALARY
AD_VP 34000


select job_id,count(employee_id) from employees group by job_id having count(employee_id)>3;

JOB _ID COUNT (EMPLOYEE _ID )
ST_CLERK 4
RESULT:
Thus the sql queries are executed successfully to find the salary calculation.


EX NO:
DATE:

QUESTION:

1) DISPLAY ENAME WHO ARE WORKING IN SALES DEPT.
2) DISPLAY EMPLOYEE NAME,DEPTNAME,SALARY AND COMM FOR THOSE
SAL IN BETWEEN
2000 TO 5000 WHILE LOCATION IS CHICAGO.
3)DISPLAY THOSE EMPLOYEES WHOSE SALARY GREATER THAN HIS
MANAGER SALARY.
4) DISPLAY THOSE EMPLOYEES WHO ARE WORKING IN THE SAME DEPT
WHERE HIS MANAGER IS WORK
5) DISPLAY THOSE EMPLOYEES WHO ARE NOT WORKING UNDER ANY
MANAGER.
NOT 4 WHILE JOINED THE COMPANY BEFORE 31-DEC-82.
6) DISPLAY GRADE AND EMPLOYEES NAME FOR THE DEPT NO 10 OR 30 BUT
GRADE IS NOT 4 WHILE JOINED THE COMPANY BEFORE 31-DEC-82.
7) UPDATE THE SALARY OF EACH EMPLOYEE BY 10% INCREMENT WHO ARE
NOT
ELIGIBLW FOR COMMISSION.
8) SELECT THOSE EMPLOYEE WHO JOINED THE COMPANY BEFORE 31-DEC-82
WHILE THEIR DEPT LOCATION IS NEWYORK OR CHICAGO
9) DISPLAY EMPLOYEE NAME,JOB,DEPARTMENT,LOCATION FOR ALL
WHO ARE WORKING AS MANAGER?
10) DISPLAY THOSE EMPLOYEES WHOSE MANAGER NAME IS JONES?
[AND ALSO DISPLAY THEIR MANAGER NAME]?





AIM:
To create the table for employees. . To find the output for given queries.
DESCRIPTION:
The Data Definition Language is used to create an object(e.g table),alter the structure of the table
and also drop the object created. A table is a unit of storage that holds the data in the form of
rows and columns.

The Data Definition Language is used to

Create the table
Alter the table
The Data manipulation Language is used to insert an object,select is used to display fields and
delete to remove objects inserted. A table is a unit of storage that holds the data in the form of
rows and columns.

The Data manipulation Language is used to

Insert
Select

QUARIES:
1) select concat(first_name,last_name) as NAME,job_id as JOB_NAME from employees
where job_id='SALES';

NAME JOB_NAME
PeterVargas SALES
EliyaZlot SALES
2)
SELECT CONCAT (first_name , last_name) as NAME ,job_id as
DEPARTMENT_NAME ,salary from employees where email='chicago' AND salary
between 2000 AND 4000;
no data found.
3) SELECT CONCAT(first_name,last_name) as NAME,job_id as
DEPARTMENT_NAME,salary from employees where email='chicago' AND salary
between 2000 AND 4000;





NAME DEPARTMENT_NAME SALARY
selvalakshmi SA_MAN 3500
4)select concat(first_name,last_name) as NAME,JOB_ID from employees where
department_id=(select department_id from employees where job_id='manager');

NAME JOB_ID
stevenking AD_PRES
Neenakochhar AD_VP
LexDehaan AD_VP
jayalakshmi manager
5)select concat(first_name,last_name) as NAME,JOB_ID from employees where
department_id!=(select department_id from employees where job_id='manager');

NAME JOB_ID
AlexanderHunold IT_PROG
BruceErnst IT_PROG
DianaLorentz IT_PROG
KebinMourgos ST_MAN
TrennaRajs ST_CLERK
CurtisDavies ST_CLERK
RandallMatos ST_CLERK
PeterVargas ST_CLERK
EleniZlotkey SA_MAN
EllenAbel SA_REP
JonathonTaylor SA_REP
JenniferWhalen AD_ASST
MichaelHartstein MK_MAN
PatFay MK_REP
ShelieyHiggins AC_MGR
WilliamGietz AC_ACCOUNT
PeterVargas SALES
EliyaZlot SALES
ramalakshmi SA_MAN
selvalakshmi SA_MAN





6) select concat(first_name,last_name) as NAME,grade from employees where
department_id=10 or department_id=30 and grade!=(select grade from employees where
grade!=4 and hire_date<'31-dec-82');



NAME GRADE
JenniferWhalen 2
7)
update employees set salary=salary+(salary*10/100) where commission_pct is null;
17 row(s) updated.
8)
select concat(first_name,last_name) as EMPLOYEE_NAME from employees where
hire_date<'31-dec-82' and email='newyork' or email='chicago';

EMPLOYEE_NAME
ramalakshmi
selvalakshmi
9)select concat(first_name,last_name) as NAME,job_id as JOB_NAME,department_id,email as
LOCATION from employees where job_id='manager';

NAME JOB_NAME DEPARTMENT_ID LOCATION
jayalakshmi manager 90 sking
10)select concat(first_name,last_name)as NAME from employees where department_id=(select
department_id from employees where job_id like '%manager' and first_name='jone');


no data found





RESULT:

Thus the data base for the given tables has been created successfully.


EX NO:
DATE:

QUESTION:
1) DISPLAY THOSE EMPLOYEE WHOSE JOINING DATE IS AVAILABLE IN
DEPTNO.
2) DISPLAY THOSE EMPLOYEES NAME AS FOLLOWS A
ALLEN
B BLAKE
3) LIST OUT THE EMPLOYEES ENAME,SAL,PF(20% OF SAL) FROM EMP;
4) CREATE TABLE EMP WITH ONLY ONE COLUMN EMPNO;
5) ADD THIS COLUMN TO EMP TABLE ENAME VRACHAR2(20)
6) OOPS I FORGOT GIVE THE PRIMARY KEY CONSTRAINT. ADD IN NOW.
7) NOW INCREASE THE LENGTH OF ENAME COLUMN TO 30 CHARACTERS.
8) ADD SALARY COLUMN TO EMP TABLE.
9) I WANT TO GIVE A VALIDATION SAYING THAT SALARY CANNOT BE
GREATER 10,000
(NOTE GIVE A NAME TO THIS CONSTRAINT)
10) FOR THE TIME BEING I HAVE DECIDED THAT I WILL NOT IMPOSE THIS
VALIDATION.MY BOSS HAS AGREED TO PAY MORE THAN 10,000.





AIM:
To create the table for employees. . To find the output for given queries.
DESCRIPTION:
The Data Definition Language is used to create an object(e.g table),alter the structure of the table
and also drop the object created. A table is a unit of storage that holds the data in the form of
rows and columns.

The Data Definition Language is used to

Create the table
Alter the table
The Data manipulation Language is used to insert an object,select is used to display fields and
delete to remove objects inserted. A table is a unit of storage that holds the data in the form of
rows and columns.
The Data manipulation Language is used to
Insert
Select



QUERIES:
1.select concat(first_name,last_name) as NAME,hire_date from employees where hire_date is
not null;

NAME HIRE_DATE
stevenking 17-JUN-87
Neenakochhar 21-SEP-89
LexDehaan 17-JAN-93
AlexanderHunold 03-JAN-90
BruceErnst 21-MAY-91
DianaLorentz 07-FEB-99
KebinMourgos 16-NOV-99
TrennaRajs 17-OCT-95
CurtisDavies 29-JAN-97





RandallMatos 15-MAR-98
PeterVargas 09-JUL-98
EleniZlotkey 29-JAN-00
EllenAbel 11-MAY-96
JonathonTaylor 24-MAR-98
KimberelyGrant 24-MAY-99
JenniferWhalen 17-SEP-87
MichaelHartstein 17-FEB-96
PatFay 17-AUG-97
ShelieyHiggins 07-JUN-94
WilliamGietz 07-JUN-94
PeterVargas 09-JUL-98
EliyaZlot 29-JAN-00
ramalakshmi 29-JAN-00
selvalakshmi 29-JAN-00
jayalakshmi 29-JAN-00


2)
select concat(first_name,last_name) as NAME from employees order by first_name;

NAME
AlexanderHunold
BruceErnst
CurtisDavies
DianaLorentz
EleniZlotkey
EliyaZlot
EllenAbel
JenniferWhalen
JonathonTaylor
KebinMourgos
KimberelyGrant
LexDehaan
MichaelHartstein
Neenakochhar





PatFay
PeterVargas
PeterVargas
RandallMatos
ShelieyHiggins
TrennaRajs
WilliamGietz
Jayalakshmi
Ramalakshmi
selvalakshmi
Stevenking
3) select concat(first_name,last_name) as NAME,salary,(salary*20)/100 as PF from
employees;

NAME SALARY PF
Stevenking 26400 5280
Neenakochhar 18700 3740
LexDehaan 18700 3740
AlexanderHunold 9900 1980
BruceErnst 6600 1320
DianaLorentz 4620 924
KebinMourgos 6380 1276
TrennaRajs 3850 770
CurtisDavies 3410 682
RandallMatos 2860 572
PeterVargas 2750 550
EleniZlotkey 10500 2100
EllenAbel 11000 2200
JonathonTaylor 8600 1720
KimberelyGrant 7000 1400
JenniferWhalen 4840 968
MichaelHartstein 14300 2860
PatFay 6600 1320
ShelieyHiggins 13200 2640
WilliamGietz 9130 1826





PeterVargas 2750 550
EliyaZlot 10500 2100
ramalakshmi 10500 2100
selvalakshmi 3500 700
jayalakshmi 3500 700
4) create table emp(empno number(20));
Table created.
5) alter table emp add(ename varchar(20));
Table altered
6) alter table emp modify(ename varchar(20) primary key);
Table altered.
7) alter table emp modify(ename varchar(30) );
desc emp;

Ta Colu Data Len Precis Sca Primary Nulla Defa Comm
ble mn Type gth ion le Key ble ult ent
EM EMP
P NO
Number - 20 0 - - -
ENA Varchar
ME 2
30 - - 1 - - -
8) alter table emp add(salary number);
desc emp;

Ta Colu Data Len Precis Sca Primary Nulla Defa Com
ble mn Type gth ion le Key ble ult ment
EM EMP
P NO
Number - 20 0 - - -
ENA Varchar
ME 2
30 - - 1 - - -
SALA
RY
Number - - - - - -
9)select concat(first_name,last_name) as NAME,salary+10000 as SALARY from employees
where salary<=10000;

NAME SALARY
AlexanderHunold 19900
BruceErnst 16600
DianaLorentz 14620





KebinMourgos 16380
TrennaRajs 13850
CurtisDavies 13410
RandallMatos 12860
PeterVargas 12750
JonathonTaylor 18600
KimberelyGrant 17000
JenniferWhalen 14840
PatFay 16600
WilliamGietz 19130
PeterVargas 12750
selvalakshmi 13500
jayalakshmi 13500

10) FOR THE TIME BEING I HAVE DECIDED THAT I WILL NOT IMPOSE THIS
VALIDATION.MY BOSS HAS AGREED TO PAY MORE THAN 10,000.
select concat(first_name,last_name) as NAME,salary+10000 as SALARY from employees
where salary>=10000;

NAME SALARY
stevenking 36400
Neenakochhar 28700
LexDehaan 28700
EleniZlotkey 20500
EllenAbel 21000
MichaelHartstein 24300
ShelieyHiggins 23200
EliyaZlot 20500
ramalakshmi 20500



RESULT:

Thus the data base for the given tables has been created successfully.


EX NO:
DATE:

QUESTION:
1) COUNT MGR AND THEIR SALARY IN EMP TABLE.
2) IN EMP TABLE ADD COMM+SAL AS TOTAL SAL .
3) SELECT ANY SALARY <3000 FROM EMP TABLE.
4) SELECT ANY SALARY <3000 FROM EMP TABLE.
5) SELECT ALL THE EMPLOYEE ORDER BY BY DEPTNO AND SAL IN
DESCENDING ORDER.
6) HOW CAN I CREATE AN EMPTY TABLE EMP1 WITH SAME STRUCTURE AS
EMP?
7) HOW TO RETRIVE RECORD WHERE SAL BETWEEN 1000 TO 2000?
8) SELECT ALL RECORDS WHERE DEPT NO OF BOTH EMP AND DEPT TABLE
MATCHES
9) IF THERE ARE TWO TABLES EMP1 AND EMP2, AND BOTH HAVE COMMON
RECORD.
HOW CAN I FETCH ALL THE RECODS BUT COMMON RECORDS ONLY ONCE?
10) HOW TO FETCH ONLY COMMON RECORDS FROM TWO TABLES EMP AND
EMP1?

AIM:
To create the table for employees. . To find the output for given queries.
DESCRIPTION:
The Data Definition Language is used to create an object(e.g table),alter the structure of the table
and also drop the object created. A table is a unit of storage that holds the data in the form of
rows and columns.

The Data Definition Language is used to

Create the table
Alter the table



The Data manipulation Language is used to insert an object,select is used to display fields and
delete to remove objects inserted. A table is a unit of storage that holds the data in the form of
rows and columns.
The Data manipulation Language is used to
Insert
Select



QUERIES:
1) COUNT MGR AND THEIR SALARY IN EMP TABLE.
select count(first_name),count(salary) from employees;

COUNT(FIRST_NAME) COUNT(SALARY)
25 25
2) IN EMP TABLE ADD COMM+SAL AS TOTAL SAL .
alter table employees add(total number(10));
update employees set total=salary+(commission_pct/100);

T
G O
EMP FIRS LAS PHON HIR SA COMM MAN DEPA R T
LOYE T _N T _N EM E _NU E _D JOB LA ISSION AGE RTME A A
E _ID AME AME AIL MBER ATE _ID RY _PCT R _ID NT _ID DE L

100 steven king

SKI
NG

515.123. 17- AD_P 240
JUN- - -
4567 87 RES 00

90 4 -

101 Neena

kochh
ar
NKO
CHH
AR
21-
515.123. AD_ 170
SEP- - 100
458 VP 00
89

90 3 -
102


103


104


107


124


141
Lex


Alexan
der


Bruce


Diana


Kebin


Trenna
Dehaa
n

Hunol
d


Ernst


Lorent
z

Mourg
os

Rajs
LDE
HAA
N
AHU
NOL
D

BER
NST

DLO
REN
TZ
KM
OUR
GOS
TRA
JS
17-
515.123. AD_ 170
JAN- - 100
4569 VP 00
93
03-
590.423. IT_P 900
JAN- - 102
4567 ROG 0
90
590.423. 21- IT_P 600
MAY - 103
4568 -91 ROG 0
07-
590.423. IT_P 420
FEB- - 103
5567 ROG 0
99
16-
650.123. ST_M 580
NOV- - 100
5234 AN 0
99
650.121. 17- ST_C 350
- 124
8009 OCT- LERK 0
90 2 -


60 1 -


60 4 -


60 3 -


50 2 -


50 1 -







95

142 Curtis

Davie CDA
s VIES

650.121. 29- ST_C 310
JAN- - 124
2994 97 LERK 0

50 4 -

143

Randal
l
RM
Matos ATO
S
15-
650.121. ST_C 260
MAR - 124
2874 LERK 0
-98

50 3 -
144 Peter
Varga
s
PVA
RGA
S
09-
650.121. ST_C 250
JUL- - 124
2004 LERK 0
98
50 2 -
149 Eleni
Zlotke
y
EZL
OTK
EY
011.44.1 29-
SA_ 105
344.4290 JAN- 0 100
MAN 00
18 00
105
80 1
00
174 Ellen Abel
EAB
EL
011.44.1 11-
644.4292 MAY
67 -96
SA_R 110
0 149
EP 00
110
80 4
00

176
Jonath
on
JTA
Taylor YLO
R
011.44.1 24-
SA_R 860
644.4292 MAR 0 149
EP 0
65 -98
860
80 3
0
178
Kimbe
rely
KGR
Grant
ANT
011.44.1 24-
644.4292 MAY
63 -99
SA_R 700
0 149
EP 0
700
- 2
0

200

Jennife Whale
r n
JWH
ALE
N
17-
515.123. AD_ 440
SEP- - 101
4444 ASST 0
87

10 2 -
201
Micha Hartst
el ein
MH
ART
STE
17-
515.123. MK_ 130
FEB- - 100
5555 MAN 00
96
20 1 -
202 Pat Fay
PFA
Y
603.123. 17- MK_ 600
AUG- - 201
6666 97 REP 0
20 5 -

205


206
Shelie
y

Willia
m
Higgi
ns


Gietz
SHI
GGI
NS

WGI
ETZ
515.123.
8080

515.123.
8181
07-
AC_
JUN-
MGR
94
07- AC_A
JUN- CCO
94 UNT
120
- 101
00

830
- 205
0

110 6 -


110 7 -
3) SELECT ANY SALARY <3000 FROM EMP TABLE.
select concat(first_name,last_name) as NAME,salary FROM employees where salary<3000;

NAME SALARY
RandallMatos 2860
PeterVargas 2750
PeterVargas 2750
4) SELECT ANY SALARY <3000 FROM EMP TABLE.
select concat(first_name,last_name) as NAME,salary from employees where salary<any
(select salary from employees where salary<3000);

NAME SALARY
PeterVargas 2750
PeterVargas 2750




5) SELECT ALL THE EMPLOYEE ORDER BY BY DEPTNO AND SAL IN
DESCENDING ORDER.
select first_name||last_name as NAME,department_id,salary from employees order by
department_id,salary desc;

NAME DEPARTMENT_ID SALARY
JenniferWhalen 10 4400
MichaelHartstein 20 13000
PatFay 20 6000
KebinMourgos 50 5800
TrennaRajs 50 3500
CurtisDavies 50 3100
RandallMatos 50 2600
PeterVargas 50 2500
AlexanderHunold 60 9000
BruceErnst 60 6000
DianaLorentz 60 4200
EllenAbel 80 11000
EleniZlotkey 80 10500
JonathonTaylor 80 8600
stevenking 90 24000
LexDehaan 90 17000
Neenakochhar 90 17000
ShelieyHiggins 110 12000
WilliamGietz 110 8300
KimberelyGrant - 7000
6) HOW CAN I CREATE AN EMPTY TABLE EMP1 WITH SAME STRUCTURE AS
EMP?
Create table emp1 as select * from employees where 1=2;
desc emp1;

Tabl Data Lengt Precisi Scal Primary Nullab Defau Comme
e Column Type h on e Key le lt nt

EMP
1


EMPLOYEE_ID Number -


10 0 - - -







FIRST_NAME Varchar2 20 - - - - -


LAST_NAME Varchar2 20 - - - - -


EMAIL Varchar2 20 - - - - -

PHONE_NUMBE
R


Varchar2 30 -


- -


- -

HIRE_DATE Date 7 - - - - -


JOB_ID Varchar2 20 - - - - -


SALARY Number - 20 0 - - -

COMMISSION_P
CT
Number - 10 0 - - -


MANAGER_ID Number - 10 0 - - -

DEPARTMENT_
ID
Number - 10 0 - - -


GRADE Varchar2 10 - - - - -


TOTAL Number - 10 0 - - -

7) HOW TO RETRIVE RECORD WHERE SAL BETWEEN 1000 TO 2000?
select concat(first_name,last_name) as NAME,salary from employees where salary between
1000 and 2000;
no data found.
8) SELECT ALL RECORDS WHERE DEPT NO OF BOTH EMP AND DEPT TABLE
MATCHES.
select employees.first_name,departments.department_id from employees inner join
departments on employees.department_id=departments.department_id;

FIRST_NAME DEPARTMENT_ID
Steven 10
Neena 10
Lex 10
Alexander 10
Bruce 10
Diana 10
Kebin 10





Trenna 10
Curtis 10
Randall 10
Peter 10
Eleni 10
Ellen 10
Jonathon 10
Jennifer 10
Michael 10
Pat 10
Sheliey 10
William 10
Peter 10
Eliya 10
Rama 10
Selva 10
Jaya 10
Steven 20
Neena 20
Lex 20
Alexander 20
Bruce 20
Diana 20


9) IF THERE ARE TWO TABLES EMP1 AND EMP2, AND BOTH HAVE COMMON
RECORD.
HOW CAN I FETCH ALL THE RECODS BUT COMMON RECORDS ONLY
ONCE?
select employees.first_name,departments.department_id from employees full outer join
departments on employees.department_id=departments.department_id;
FIRST_NAME DEPARTMENT_ID
Jennifer 10
Pat 20
Michael 20
Peter 50
Peter 50





Randall 50
Curtis 50
Trenna 50
Kebin 50
Diana 60
Bruce 60
Alexander 60
selva 80
rama 80
Eliya 80
Jonathon 80
10) HOW TO FETCH ONLY COMMON RECORDS FROM TWO TABLES EMP
AND EMP1?
select employees.first_name,departments.department_id from employees inner join
departments on employees.department_id=departments.department_id;
FIRST_NAME DEPARTMENT_ID
steven 90
Neena 90
Lex 90
Alexander 60
Jennifer 10
Michael 20
Pat 20
Sheliey 110
William 110
Peter 50
Eliya 80
rama 80
selva 80
jaya 90


RESULT:

Thus the data base for the given tables has been created successfully.


EX NO:
DATE:

QUESTION:
1) GET LENGTH OF FIRST_NAME FROM EMPLOYEE TABLE
2) GET FIRST_NAME FROM EMPLOYEE TABLE AFTER REPLACING 'O' WITH '$'
3) GET FIRST_NAME AND LAST_NAME AS SINGLE COLUMN FROM EMPLOYEE
TABLE
SEPARATED BY A '_'
4) GET FIRST_NAME ,JOINING YEAR,JOINING MONTH AND JOINING DATE FROM
EMPLOYEE TABLE
5) GET ALL EMPLOYEE DETAILS FROM THE EMPLOYEE TABLE ORDER BY
FIRST_NAME ASCENDING.
6) GET ALL EMPLOYEE DETAILS FROM THE EMPLOYEE TABLE ORDER BY
FIRST_NAME DESCENDING.
7) GIVE THE COMMAND TO ADD THE CONSTRAINT.
ALTER TABLE NEWEMP ADD(PH_NO NUMBER(20));
8) CREATE TABLE CALLED AS NEWEMP. USING SINGLE COMMAND CREATE
THIS TABLE A. AS WELL AS GET DATA INTO THIS TABLE(USE CREATE TABLE
AS);
9) DELETE THE ROWS OF EMPLOYEES WHO ARE WORKING IN THE COMPANY
FOR MORE A. THAN 2 YEARS.
10) PROVIDE A COMMISSION(10% COMM OF SAL) TO EMPLOYEES WHO ARE
NOT
EARNING ANY COMMISSION.
A. IF ANY EMPLOYEE HAS COMMISSION HIS COMMISSION SHOULD BE
INCREMENTED BY 10% OF HIS SALARY.





AIM:
To create the table for employees. . To find the output for given queries.
DESCRIPTION:
The Data Definition Language is used to create an object(e.g table),alter the structure of the table
and also drop the object created. A table is a unit of storage that holds the data in the form of
rows and columns.

The Data Definition Language is used to

Create the table
Alter the table
The Data manipulation Language is used to insert an object,select is used to display fields and
delete to remove objects inserted. A table is a unit of storage that holds the data in the form of
rows and columns.
The Data manipulation Language is used to
Insert
Select



QUARIES:
1) GET LENGTH OF FIRST_NAME FROM EMPLOYEE TABLE
select first_name,length(first_name) as length from employees;

FIRST_NAME LENGTH
steven 6
Neena 5
Lex 3
Alexander 9
Bruce 5
Diana 5
Kebin 5
Trenna 6
Curtis 6





Randall 7
Peter 5
Eleni 5
Ellen 5
Jonathon 8
Kimberely 9
Jennifer 8
Michael 7
Pat 3
Sheliey 7
William 7
Peter 5
Eliya 5
rama 4
selva 5
jaya 4
2) GET FIRST_NAME FROM EMPLOYEE TABLE AFTER REPLACING 'O' WITH
'$'
select replace(first_name,'o','$') from employees;

REPLACE(FIRST_NAME,'O','$')
steven
Neena
Lex
Alexander
Bruce
Diana
Kebin
Trenna
Curtis
Randall
Peter
Eleni
Ellen
J$nath$n



Kimberely
Jennifer
Michael
Pat
Sheliey
William
Peter
Eliya
rama
selva
jaya
3) GET FIRST_NAME AND LAST_NAME AS SINGLE COLUMN FROM
EMPLOYEE TABLE
SEPARATED BY A '_'
select concat(first_name,concat('_',last_name)) as name from employees;

NAME
steven_king
Neena_kochhar
Lex_Dehaan
Alexander_Hunold
Bruce_Ernst
Diana_Lorentz
Kebin_Mourgos
Trenna_Rajs
Curtis_Davies
Randall_Matos
Peter_Vargas
Eleni_Zlotkey
Ellen_Abel
Jonathon_Taylor
Kimberely_Grant
Jennifer_Whalen
Michael_Hartstein
Pat_Fay



Sheliey_Higgins
William_Gietz
Peter_Vargas
Eliya_Zlot
rama_lakshmi
selva_lakshmi
jaya_lakshmi
4) GET FIRST_NAME ,JOINING YEAR,JOINING MONTH AND JOINING DATE
FROM
EMPLOYEE TABLE
select concat(first_name,last_name) as NAME,hire_date as joining_date from
employees;

NAME JOINING _DATE
LexDehaan 17-JAN-93
AlexanderHunold 03-JAN-90
BruceErnst 21-MAY-91
DianaLorentz 07-FEB-99
KebinMourgos 16-NOV-99
TrennaRajs 17-OCT-95
CurtisDavies 29-JAN-97
RandallMatos 15-MAR-98
PeterVargas 09-JUL-98
EleniZlotkey 29-JAN-00
EllenAbel 11-MAY-96
JonathonTaylor 24-MAR-98
KimberelyGrant 24-MAY-99
JenniferWhalen 17-SEP-87
MichaelHartstein 17-FEB-96
PatFay 17-AUG-97
ShelieyHiggins 07-JUN-94
WilliamGietz 07-JUN-94
stevenking 17-JUN-87
Neenakochhar 21-SEP-89
5) GET ALL EMPLOYEE DETAILS FROM THE EMPLOYEE TABLE ORDER BY
FIRST_NAME ASCENDING.
select *from employees order by first_name ;

EMPL FIRS LAST PHONE HIR SA COMMI MAN DEPAR TO
OYEE T _NA _NA EM _NUMB E _D JOB _ LA SSION _ AGER TMENT TA
_ID ME ME AIL ER ATE ID RY PCT _ID _ID L

103
Alexan Hunol AHU 590.423.4
der d NOL 567
03- IT_PR
9900 - 102 60 -
JAN- OG







D 90

104 Bruce Ernst

BER
NST

590.423.4 21- IT_PR
MAY- 6600 - 103
568 91 OG

60 -

142 Curtis Davies

CDA
VIES

650.121.2 29- ST_C
JAN- 3410 - 124
994 97 LERK

50 -

107 Diana

Lorent
z
DLO
REN
TZ
07-
590.423.5 IT_PR
FEB- 4620 - 103
567 OG
99

60 -
149 Eleni
Zlotke
y
EZL
OTK
EY
011.44.13 29-
SA_M 1050
44.42901 JAN- 0 100
AN 0
8 00
105
80
00
EZL
145 Eliya Zlot OTK
EY
011.44.13 29-
44.42901 JAN-
8 00
SALE 1050
S 0
0 100
105
80
00

174 Ellen Abel

EAB
EL
011.44.16 11-
44.42926 MAY-
7 96

SA_R 1100
0 149
EP 0

110
80
00

200

Jennife Whale
r n
JWH
ALE
N
17-
515.123.4 AD_A
SEP- 4840 - 101
444 SST
87

10 -
176
Jonatho
n
JTA
Taylor YLO
R
011.44.16 24-
SA_R
44.42926 MAR- 8600 0 149
EP
5 98
860
80
0
124 Kebin
Mourg
os
KMO
URG
OS
16-
650.123.5 ST_M
NOV- 6380 - 100
234 AN
99
50 -
178
Kimber
ely
KGR
Grant
ANT
011.44.16 24-
44.42926 MAY-
3 99
SA_R
7000 0 149
EP
700
-
0

102


201


101


202


144


144


143


205


141


206

Lex


Michae
l


Neena


Pat


Peter


Peter


Randall


Sheliey


Trenna


Willia
m
Dehaa
n

Hartste
in

kochha
r


Fay


Vargas


Vargas


Matos


Higgin
s


Rajs


Gietz
LDE
HAA
N
MHA
RTS
TE
NKO
CHH
AR

PFA
Y

PVA
RGA
S
PVA
RGA
S

RMA
TOS

SHIG
GINS

TRAJ
S

WGI
ETZ
515.123.4
569

515.123.5
555

515.123.4
58

603.123.6
666

650.121.2
004

650.121.2
004

650.121.2
874

515.123.8
080

650.121.8
009

515.123.8
181
17-
AD_V 1870
JAN- - 100
P 0
93
17-
MK_ 1430
FEB- - 100
MAN 0
96
21-
AD_V 1870
SEP- - 100
P 0
89
17- MK_R
AUG- 6600 - 201
97 EP
09-
SALE
JUL- 2750 - 124
S
98
09-
ST_C
JUL- 2750 - 124
LERK
98
15- ST_C
MAR- 2860 - 124
98 LERK
07- AC_M 1320
JUN- - 101
94 GR 0
17- ST_C
OCT- 3850 - 124
95 LERK
07- AC_A
JUN- CCOU 9130 - 205
94 NT

90 -


20 -


90 -


20 -


50 -


50 -


50 -


110 -


50 -


110 -








156 jaya







lakshm
i






011.44.13 29-
Sking 44.42901 JAN-
8 00







manag 350
3500 0 560 90
er 0

189 rama

lakshm Chica
i go
011.44.13 29-
44.42901 JAN-
8 00

SA_M 1050 105
0 100 80
AN 0 00

187 selva

lakshm Chica
i go
011.44.13 29-
44.42901 JAN-
8 00

SA_M 350
3500 0 100 80
AN 0

100 steven king

SKIN 515.123.4
G 567
17- AD_P 2640
JUN- - - 90 -
87 RES 0
6) GET ALL EMPLOYEE DETAILS FROM THE EMPLOYEE TABLE ORDER BY
FIRST_NAME DESCENDING.
select *from employees order by first_name desc;

EMPL FIRS LAST PHONE HIR SA COMMI MAN DEPAR TO
OYEE T _NA _NA EM _NUMB E _D JOB _ LA SSION _ AGER TMENT TA
_ID ME ME AIL ER ATE ID RY PCT _ID _ID L

100 steven king

SKIN
G

515.123.4 17- AD_P 2640
JUN- - -
567 87 RES 0

90 -

187 selva

lakshm Chica
i go
011.44.13 29-
44.42901 JAN-
8 00

SA_M
3500 0 100
AN

350
80
0

189 rama

lakshm Chica
i go
011.44.13 29-
44.42901 JAN-
8 00

SA_M 1050
0 100
AN 0

105
80
00

156 jaya

lakshm
i

Sking
011.44.13 29-
44.42901 JAN-
8 00

manag
3500 0 560
er

350
90
0

206


141


205


143


144


144


202


101


201

102

Willia
m


Trenna


Sheliey


Randall


Peter


Peter


Pat


Neena


Michae
l

Lex

Gietz


Rajs


Higgin
s


Matos


Vargas


Vargas


Fay


kochha
r

Hartste
in

Dehaa

WGI
ETZ

TRAJ
S

SHIG
GINS

RMA
TOS

PVA
RGA
S
PVA
RGA
S

PFA
Y

NKO
CHH
AR
MHA
RTS
TE
LDE

515.123.8
181

650.121.8
009

515.123.8
080

650.121.2
874

650.121.2
004

650.121.2
004

603.123.6
666

515.123.4
58

515.123.5
555

515.123.4
07- AC_A
JUN- CCOU 9130 - 205
94 NT
17- ST_C
OCT- 3850 - 124
95 LERK
07- AC_M 1320
JUN- - 101
94 GR 0
15- ST_C
MAR- 2860 - 124
98 LERK
09-
ST_C
JUL- 2750 - 124
LERK
98
09-
SALE
JUL- 2750 - 124
S
98
17- MK_R
AUG- 6600 - 201
97 EP
21-
AD_V 1870
SEP- - 100
P 0
89
17-
MK_ 1430
FEB- - 100
MAN 0
96
17- AD_V 1870 - 100

110 -


50 -


110 -


50 -


50 -


50 -


20 -


90 -


20 -

90 -







n HAA 569 JAN- P 0
N 93

178

Kimber
ely

KGR
Grant
ANT
011.44.16 24-
44.42926 MAY-
3 99

SA_R
7000 0 149
EP

700
-
0

124 Kebin

Mourg
os
KMO
URG
OS
16-
650.123.5 ST_M
NOV- 6380 - 100
234 AN
99

50 -
176
Jonatho
n
JTA
Taylor YLO
R
011.44.16 24-
SA_R
44.42926 MAR- 8600 0 149
EP
5 98
860
80
0
200
Jennife Whale
r n
JWH
ALE
N
17-
515.123.4 AD_A
SEP- 4840 - 101
444 SST
87
10 -
174 Ellen Abel
EAB
EL
011.44.16 11-
44.42926 MAY-
7 96
SA_R 1100
0 149
EP 0
110
80
00
EZL
145 Eliya Zlot OTK
EY
011.44.13 29-
44.42901 JAN-
8 00
SALE 1050
S 0

0 100
105
80
00

149 Eleni

Zlotke
y
EZL
OTK
EY
011.44.13 29-
SA_M 1050
44.42901 JAN- 0 100
AN 0
8 00

105
80
00
107 Diana
Lorent
z
DLO
REN
TZ
07-
590.423.5 IT_PR
FEB- 4620 - 103
567 OG
99
60 -
142 Curtis Davies
CDA
VIES
650.121.2 29- ST_C
JAN- 3410 - 124
994 97 LERK
50 -

104 Bruce Ernst

BER
NST

590.423.4 21- IT_PR
MAY- 6600 - 103
568 91 OG

60 -

103

Alexan Hunol
der d
AHU
NOL
D
03-
590.423.4 IT_PR
JAN- 9900 - 102
567 OG
90

60 -
7) GIVE THE COMMAND TO ADD THE CONSTRAINT.
ALTER TABLE NEWEMP ADD(PH_NO NUMBER(20));
desc newemp;
Data Lengt Precisi Scal Primary Nullab Defau Comme
Table Column Type h on e Key le lt nt
NEWE
MP
EMPLOYEE_ID Number - 10 0 - - -
FIRST_NAME Varchar2 20 - - - - -
LAST_NAME Varchar2 20 - - - - -
EMAIL Varchar2 20 - - - - -
PHONE_NUMB
ER
Varchar2 30 - - - - -
HIRE_DATE Date 7 - - - - -
JOB_ID Varchar2 20 - - - - -
SALARY Number - 20 0 - - -
COMMISSION_
PCT
Number - 10 0 - - -
MANAGER_ID Number - 10 0 - - -
DEPARTMENT_
ID
Number - 10 0 - - -








TOTAL Number - 10 0 - - -
PH_NO Number - 20 0 - - -

8) CREATE TABLE CALLED AS NEWEMP. USING SINGLE COMMAND
CREATE THIS TABLE A. AS WELL AS GET DATA INTO THIS TABLE(USE
CREATE TABLE AS);
create table newemp as select *from employees;
select *from newemp;

EMPL FIRS LAST PHONE HIR SA COMMI MAN DEPAR TO
OYEE T _NA _NA EM _NUMB E _D JOB _ LA SSION _ AGER TMENT TA
_ID ME ME AIL ER ATE ID RY PCT _ID _ID L

100 steven king

SKIN
G

515.123.4 17- AD_P 2640
JUN- - -
567 87 RES 0

90 -

101 Neena

kochha
r
NKO
CHH
AR
21-
515.123.4 AD_V 1870
SEP- - 100
58 P 0
89

90 -
102 Lex
Dehaa
n
LDE
HAA
N
17-
515.123.4 AD_V 1870
JAN- - 100
569 P 0
93
90 -
103
Alexan Hunol
der d
AHU
NOL
D
03-
590.423.4 IT_PR
JAN- 9900 - 102
567 OG
90
60 -
104 Bruce Ernst BER
NST
590.423.4 21- IT_PR
MAY- 6600 - 103
568 91 OG
60 -

107 Diana
Lorent
z
DLO
REN
TZ
07-
590.423.5 IT_PR
FEB- 4620 - 103
567 OG
99

60 -
124


141


142


143


144


149


174


176


178
Kebin


Trenna


Curtis


Randall


Peter


Eleni


Ellen


Jonatho
n

Kimber
ely
Mourg
os


Rajs


Davies


Matos


Vargas


Zlotke
y


Abel


Taylor


Grant
KMO
URG
OS

TRAJ
S

CDA
VIES

RMA
TOS

PVA
RGA
S
EZL
OTK
EY

EAB
EL

JTA
YLO
R

KGR
ANT
650.123.5
234

650.121.8
009

650.121.2
994

650.121.2
874

650.121.2
004

011.44.13
44.42901
8
011.44.16
44.42926
7
011.44.16
44.42926
5
011.44.16
44.42926
3
16-
ST_M
NOV- 6380 - 100
AN
99
17- ST_C
OCT- 3850 - 124
95 LERK
29- ST_C
JAN- 3410 - 124
97 LERK
15- ST_C
MAR- 2860 - 124
98 LERK
09-
ST_C
JUL- 2750 - 124
LERK
98
29-
SA_M 1050
JAN- 0 100
AN 0
00
11-
SA_R 1100
MAY- 0 149
EP 0
96
24-
SA_R
MAR- 8600 0 149
EP
98
24-
SA_R
MAY- 7000 0 149
EP
99
50 -


50 -


50 -


50 -


50 -


105
80
00

110
80
00

860
80
0

700
-
0








200







Jennife Whale
r n






JWH
ALE
N






17-
515.123.4 AD_A
SEP- 4840 - 101
444 SST
87







10 -
201
Michae Hartste
l in
MHA
RTS
TE
17-
515.123.5 MK_ 1430
FEB- - 100
555 MAN 0
96
20 -
202 Pat Fay
PFA
Y
603.123.6 17- MK_R
AUG- 6600 - 201
666 97 EP
20 -

205 Sheliey
Higgin SHIG
s GINS
515.123.8 07- AC_M 1320
JUN- - 101
080 94 GR 0

110 -

206

Willia
m

WGI
Gietz
ETZ

515.123.8
181
07- AC_A
JUN- CCOU 9130 - 205
94 NT

110 -
PVA
144 Peter Vargas RGA
S

650.121.2
004
09-
SALE
JUL- 2750 - 124
S
98

50 -
EZL
145 Eliya Zlot OTK
EY
011.44.13 29-
44.42901 JAN-
8 00
SALE 1050
S 0
0 100
105
80
00

189 rama

lakshm chica
i go
011.44.13 29-
44.42901 JAN-
8 00

SA_M 1050
0 100
AN 0

105
80
00

187 selva

lakshm chica
i go
011.44.13 29-
44.42901 JAN-
8 00

SA_M
3500 0 100
AN

350
80
0

156 jaya

lakshm
i

sking
011.44.13 29-
44.42901 JAN-
8 00

manag
3500 0 560
er

350
90
0
9) DELETE THE ROWS OF EMPLOYEES WHO ARE WORKING IN THE
COMPANY FOR MORE A. THAN 2 YEARS.
delete from employees where (sysdate-hire_date)/365>2;
25 row(s) deleted.
select *from employees;
no data found.
10) PROVIDE A COMMISSION(10% COMM OF SAL) TO EMPLOYEES WHO
ARE NOT
EARNING ANY COMMISSION.
A. IF ANY EMPLOYEE HAS COMMISSION HIS COMMISSION SHOULD BE
INCREMENTED BY 10% OF HIS SALARY.



update employees set commission_pct=(10*commission_pct/100) where commission_pct is
null;select concat(first_name,last_name) as NAME,commission_pct from employees;
update employees set commission_pct=(10*salary/100) where commission_pct is not null;





NAME COMMISSION_PCT
stevenking 2640
Neenakochhar 1870
LexDehaan 1870
AlexanderHunold 990
BruceErnst 660
DianaLorentz 462
KebinMourgos 638
TrennaRajs 385
CurtisDavies 341
RandallMatos 286
PeterVargas 275
EleniZlotkey 1050
EllenAbel 1100
JonathonTaylor 860
KimberelyGrant 700
JenniferWhalen 484
MichaelHartstein 1430
PatFay 660
ShelieyHiggins 1320
WilliamGietz 913
PeterVargas 275
EliyaZlot 1050
ramalakshmi 1050
selvalakshmi 350
jayalakshmi 350






RESULT:

Thus the data base for the given tables has been created successfully.


EX NO:
DATE:

QUESTION:

Suppose that we have a relation marks(ID, score) and we wish to assign grades to students
based on the score as follows: grade F if score < 40, grade C if 40 score < 60, grade B if
60 score < 80, and grade A if 80 score. Write SQL queries to do the following:
a. Display the grade for each student, based on the marks relation. b. Find the number of
students with each grade.

AIM:

To maintain mark and grade of students.

DESCRIPTION:
The Data Definition Language is used to create an object(e.g table),alter the structure of the table
and also drop the object created. A table is a unit of storage that holds the data in the form of rows
and columns.
The Data Definition Language is used to
Create the table
Alter the table
The Data manipulation Language is used to insert an object,select is used to display fields and
delete to remove objects inserted. A table is a unit of storage that holds the data in the form of
rows and columns.
The Data manipulation Language is used to
Insert
Select

SYNTAX:

CREATEING TABLE:

Create table table_name(column_name1 <data_type1>,column_name2 <data_type2);

ALTERING TABLE:





Alter table table_name add(column_name <data_type>);

VIEW TABLE:

Select * from table_name;

QUERIES:

QUERY 1:
create table student_details(student_name varchar(18),id_num number(10),score
number(10),grade varchar(10));
Table created.
select * from student_details;

STUDENT_NAME ID_NUM SCORE GRADE
Shanmugam 143 100 A
Suresh 144 80 B
Senthil 145 60 C
Hari 146 80 B
Prabhu 147 35 F
Raj 148 72 B
Pari 149 28 F


QUERY 2:

A)select id_num, case when score<40 then 'F' when score<60 then 'C' when score<80 then 'B'
else 'A' end from student_details;

ID_N CASEWHENSCORE<40THEN'F'WHENSCORE<60THEN'C'WHEN
UM SCORE<80THEN'B'ELSE'A'END
143 A
144 A
145 B
146 A
147 F
148 B
149 F







QUERY 3:

B)with grade as(select id_num, case when score<40 then 'F' when score<=60 then 'C' when
score<=80 then 'B' else 'A' end as grade from student_details)select grade,count(id_num)from
grade group by grade;

GRADE COUNT(ID_NUM)
A 1
B 3
C 1
F 2
























RESULT:

Thus the data base for the given tables has been created successfully.


EX NO:
DATE:

QUESTION:

Consider the following table with rows as an example:
Table Name: Products
ProductId Price

1 10
1 10
2 20
3 30
3 30
1. Delete the rows using row id
2. Delete using temp table and distinct
3. Delete using temp table and Row Number analytic function. Consider the following table with
rows as an example:
Value
123456
Output1:
product

6
24
60
120
Output2: Max_produt
120
4. Find out the product of the 3 consecutive digits and display them in separate rows.
5. Find out the Max prodcut of the 3 consecutive digits and print it.





AIM:

To create tables and enter the value. To find the output for given queries.

DESCRIPTION:
The Data Definition Language is used to create an object(e.g table),alter the structure of the table
and also drop the object created. A table is a unit of storage that holds the data in the form of
rows and columns.
The Data Definition Language is used to
Create the table
Alter the table
The Data manipulation Language is used to insert an object,select is used to display fields and
delete to remove objects inserted. A table is a unit of storage that holds the data in the form of
rows and columns.
The Data manipulation Language is used to
Insert
Select

SYNTAX:

CREATEING TABLE:

Create table table_name(column_name1 <data_type1>,column_name2 <data_type2);

ALTERING TABLE:

Alter table table_name add(column_name <data_type>);

VIEW TABLE:

Select * from table_name;


QUERIES:
QUERY 1:
create table products(product_idnumber,price number(2));
insert into products values(1,10);
insert into products values(1,10);
insert into products values(2,20);
insert into products values(3,30);
insert into products values(3,30);
select * from products;










delete from products where product_id in(1,2,3);

5 row(s) deleted.

0.00 seconds
QUERY 2:
create table product_temp(product_id number primary key,price number(2));
desc temp;







truncate table products;

Table truncated.






0.00 seconds
insert into products select * from product_temp;
select * from products;








QUERY 3:

Create tableproducts_temp AsSelect product_id, priceFrom(Select product_id, price,
row_number() over (partition by product_id order by price) group_rank From products
)
Where group_rank = 1;
Select * from products_temp;







QUERY 4:

select (TO_NUMBER(SUBSTR (value,l, 1)))*(TO_NUMBER(SUBSTR (value,l+1,
1)))*(TO_NUMBER(SUBSTR(value,l+2, 1))) from digits ,(select level l from dual connect by
level <= 6-2);





select MAX((TO_NUMBER(SUBSTR (value,l, 1)))*
(TO_NUMBER(SUBSTR (value,l+1, 1)))*



(TO_NUMBER(SUBSTR (value,l+2, 1))))
from digits ,
(select level l from dual connect by level <= 6-2);



































RESULT:

Thus the data base for the given tables has been created successfully.


EX NO:
DATE:
QUESTION:
i) Write a query using SYSDATE.
ii) Write a query using Arithmetic functions with date. iii)
Write a query using MONTHS_BETWEEN.
iv) Write a query using ADD_MONTHS.
v) Write a query using NEXT_DAY.

AIM:

To create tables and enter the value. To find the output for given queries.

DESCRIPTION:
The Data Definition Language is used to create an object(e.g table),alter the structure of the table
and also drop the object created. A table is a unit of storage that holds the data in the form of
rows and columns.
The Data Definition Language is used to
Create the table
Alter the table
The Data manipulation Language is used to insert an object,select is used to display fields and
delete to remove objects inserted. A table is a unit of storage that holds the data in the form of
rows and columns.
The Data manipulation Language is used to
Insert
Select

SYNTAX:

CREATEING TABLE:

Create table table_name(column_name1 <data_type1>,column_name2 <data_type2);

ALTERING TABLE:

Alter table table_name add(column_name <data_type>);





VIEW TABLE:

Select * from table_name;

QUERIES:

1)selectsysdate from dual;

SYSDATE
28-MAR-14
1 rows returned in 0.00
seconds
2)select ADD_MONTHS ('1-jan-2014',2) from dual;

ADD_MONTHS('1-JAN-2014',2)
01-MAR-14
1 rows returned in 0.01
seconds
3)select MONTHS_BETWEEN ('1-jan-2014','1-apr-2014') from dual;

MONTHS_BETWEEN('1 -JAN-2014','1 -APR-2014')
-3
1 rows returned in 0.00
seconds
4)
select NEXT_DAY ('29-march-2014',2) from dual;

NEXT_DAY('29-MARCH -2014',2)
31-MAR-14
1 rows returned in 0.02
seconds
5)

select NEXT_DAY ('3-APR-2014','MONDAY') from dual;

NEXT_DAY('3 -APR-2014','MONDAY')
07-APR-14
1 rows returned in 0.00 seconds


RESULT:

Thus the data base for the given tables has been created successfully.


EX NO:
DATE:
QUESTION:
i) Give all the customers who lives in Canada and sort by customer_id.. ii)
List all different customers who made bookings.
iii) Display all currency exchange rate is greater than 1. Please sort them by
from_currency and to_currency.
AIM:
To create tables and enter the value. To find the output for given queries.

DESCRIPTION:
The Data Definition Language is used to create an object(e.g table),alter the structure of the table
and also drop the object created. A table is a unit of storage that holds the data in the form of
rows and columns.
The Data Definition Language is used to
Create the table
Alter the table
The Data manipulation Language is used to insert an object,select is used to display fields and
delete to remove objects inserted. A table is a unit of storage that holds the data in the form of
rows and columns.
The Data manipulation Language is used to
Insert
Select

SYNTAX:

CREATEING TABLE:

Create table table_name(column_name1 <data_type1>,column_name2 <data_type2);

ALTERING TABLE:

Alter table table_name add(column_name <data_type>);





VIEW TABLE:

Select * from table_name;

QUERY:
Query 1: Give all the customers who lives in Canada and sort by customer_id.
SELECT CUSTID AS CUSTOMER_ID FROM CUSTOMER WHERE COUNTRY =
'Canada' ORDER BY CUSTID
CUSTOMER_ID
4


Query 2: List all different customers who made bookings.
SELECT DISTINCT CUSTID AS CUSTOMER_ID FROM BOOKING

CUSTOMER_ID
1
2
5
4

Query 3: Display all currency exchange rate is greater than 1. Please sort them by
from_currency and to_currency.
SELECT FCURR AS FROM_CURRENCY,TCURR AS TO_CURRENCY,EXCHRATE AS
EXCHANGE_RATE FROM CURRENCY WHERE EXCHRATE > 1 ORDER BY
FCURR,TCURR

FROM_CURRENCY TO_CURRENCY EXCHANGE_RATE
$45 700 2000
$88 800 3000
$98 900 1000




RESULT:

Thus the data base for the given tables has been created


EX NO:
DATE:
QUESTION:
1) create a view 'agentview' as the table 'agents'.
2) create a view 'agentview' as the table 'agents' and the working_area must be
'Bangalore'.
Karpagam technical academy Page 1
Dbms -Product session 4.2-lab exercise
3) create a view 'agentview' with the columns agent_code, agent_name and
working_area of the table 'agents' 'working_area' must be NewYork.
4) create a view 'agentview' as the table 'agents' and the 'working_area' must be '
'Bangalore' and 'commission' must be greater than 1.
5) create a view 'agentview' as the table 'agents' with 'agent_code' must be any of the
following agent_codes - 'A006', 'A004', 'A001', 'A009'.

AIM:
To create tables and enter the value. To find the output for given queries.

DESCRIPTION:
The Data Definition Language is used to create an object(e.g table),alter the structure of the table
and also drop the object created. A table is a unit of storage that holds the data in the form of
rows and columns.
The Data Definition Language is used to
Create the table
Alter the table
The Data manipulation Language is used to insert an object,select is used to display fields and
delete to remove objects inserted. A table is a unit of storage that holds the data in the form of
rows and columns.
The Data manipulation Language is used to
Insert
Select





SYNTAX:

CREATEING TABLE:

Create table table_name(column_name1 <data_type1>,column_name2 <data_type2);

ALTERING TABLE:

Alter table table_name add(column_name <data_type>);

VIEW TABLE:

Select * from table_name;

QUERIES:

QUERY 1:

Create table agents (agent_code number(9),agent_namevarchar(10),working_area
varchar2(9),commission number(9),phone_no number(20));
Table created.
Insert into agents values(1007,'ramsundhar','banglore',10,07725814763);1 row(s) inserted.
Insert into agents values(1008,'Alex','London',20,07512458969);
1 row(s) inserted.
Insert into agents values(1003,'Alford','NewYork',25,0722388644);
1 row(s) inserted.
Insert into agents values(1006,'RaviKumar','chennai',25,04425874365);
1 row(s) inserted.
1) create view agent_details as select agent_code,agent_name,working_area,commission
from agents;
View created.
select * from agent_details;

AGENT_CODE AGENT_NAME WORKING_AREA COMMISSION
1007 ramsundhar banglore 10
1008 Alex London 20
1003 Alford NewYork 25
1006 RaviKumar chennai 25
4 rows returned in 0.04 seconds







QUERY 2:

select working_area from agent_details where working_area='banglore';

WORKING_AREA
banglore


QUERY 3:

select agent_code,agent_name,working_area from agent_details where
working_area='NewYork';

AGENT_CODE AGENT_NAME WORKING_AREA
1003 Alford NewYork
1 rows returned in 0.00 seconds


QUERY 4:

select * from agent_details where working_area='banglore' AND commission >= 1;

AGENT_COD AGENT_NAM WORKING_ARE COMMISSIO
E E A N
1007 ramsundhar banglore 10
1 rows returned in 0.00
seconds
QUERY 5:

select agent_code from agent_details where agent_code IN (1006,1004,1001,1009);

AGENT_CODE
1006






RESULT:

Thus the data base for the given tables has been created successfully.


EX NO:
DATE:
QUESTION:
1. List last name of all managers.

2. List last and first names of all customers.
3. Give a query that answers the question "Is any of our employee also our customer"?

AIM:
To write sql queries for the above questions.
DESCRIPTION:
The Data Definition Language is used to create an object(e.g table),alter the structure
of the table and also drop the object created. A table is a unit of storage that holds the data in the
form of rows and columns.
The Data Definition Language is used to
Create the table,
Alter the table,
Truncate the table,
Drop the table.





QUERY1:
select LAST_NAME from employee where job='manager';

LAST _NAME
King
Kochhar
Hunold
Ernst


QUERY2:
select fname,lname from customer;

FNAME LNAME
sara nira
deeps karthik
aser uaisn
ninji asdgh
opolil cxvb


QUERY3:
select fname,lname from customer where cus_name=e_name; no
data found;













RESULT:
Thus the sql queries are was written and output verified successfully.

S-ar putea să vă placă și