0% found this document useful (0 votes)
2 views15 pages

Create A Table Worker45 With A Following Attributes: Ecode, Name, Design, Plevel, Doj, Dob

The document outlines a series of SQL commands for creating and manipulating two tables, worker45 and paylevel45, including inserting records, displaying data, and performing various queries. It also includes commands for altering tables, updating records, and deleting data. Additionally, it demonstrates calculations and string manipulations using SQL functions.

Uploaded by

Rupesh Prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views15 pages

Create A Table Worker45 With A Following Attributes: Ecode, Name, Design, Plevel, Doj, Dob

The document outlines a series of SQL commands for creating and manipulating two tables, worker45 and paylevel45, including inserting records, displaying data, and performing various queries. It also includes commands for altering tables, updating records, and deleting data. Additionally, it demonstrates calculations and string manipulations using SQL functions.

Uploaded by

Rupesh Prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

1.

Create a table worker45 with a following attributes:


ecode,name,design,plevel,doj,dob.
SQL> create table worker45(ecode int,name char(15),design char(12),plevel char(4), doj date,dob date);

Table created.

2. Insert values for the table worker45.


SQL> insert into worker45 values(11,'radhe shyam','supervisor','p001','13-sep-2004','23-aug-1981');

1 row created.

SQL> insert into worker45 values(12,'chander nath','operator','p002','22-feb-1981','12-july-1987');

1 row created.

SQL> insert into worker45 values(13,'fizza','operator','p003','14-june-2010','14-oct-1983');

1 row created.

SQL> insert into worker45 values(14,'ameen ahmed','mechanic','p004','21-aug-2006','13-mar-1984');

1 row created.

SQL> insert into worker45 values(15,'sanya','clerk','p005','19-dec-2005','09-jun-1983');

1 row created.

3. create a table paylevel45 with the following


attributes:plevel,pay,allowance.
SQL> create table paylevel45 (plevel char(4),pay int,allowance int);

Table created.

1
4. Insert the values for the table paylevel45.
SQL> insert into paylevel45 values('p001',26000,12000);

1 row created.

SQL> insert into paylevel45 values('p002',22000,10000);

1 row created.

SQL> insert into paylevel45 values('p003',12000,6000);

1 row created.

5. Display all the tuples of the table worker45.


SQL> select*from worker45;

ECODE NAME DESIGN PLEV DOJ DOB

---------- --------------- ------------ ------ -------------- -------------

11. radhe shyam supervisor p001 13-SEP-04 23-AUG-81

12. chander nath operator p002 22-FEB-81 12-JUL-87

13. fizza operator p003 14-JUN-10 14-OCT-83

14. ameen ahmed mechanic p004 21-AUG-06 13-MAR-84

15. sanya clerk p005 19-DEC-05 09-JUN-83

2
6. Display all the tuples of the table paylevel45.
SQL> select*from paylevel45;

PLEV PAY ALLOWANCE

---- ---------- ----------

p001 26000 12000

p002 22000 10000

p003 12000 6000

7. Display distinct designation from the table worker45.


SQL> select distinct design from worker45;

DESIGN

------------

clerk

mechanic

supervisor

operator

8. Display all the values of the attributes designation from the worker45.
SQL> select all design from worker45;

DESIGN

------------

supervisor

operator

operator

mechanic

clerk

3
9. To display the details of name,designation whose plevel is p003.
SQL> select name,design from worker45 where plevel='p003';

NAME DESIGN

------------ ------------

fizza operator

10. To display the details of name and designation whose plevel is either p001
or p002.
SQL> select name,design from worker45 where plevel='p001' or plevel='p002';

NAME DESIGN

--------------- ------------

radhe shyam supervisor

chander nath operator

11. To display the details of the name and designation whose plevel are p001
and p002.
SQL> select name,design from worker45 where plevel in('p001','p002');

NAME DESIGN

--------------- ------------

radhe shyam supervisor

chander nath operator

4
12. To display the details of the name and designation whose plevel are not
p001 and p002.
SQL> select name,design from worker45 where plevel not in('p001','p002');

NAME DESIGN

--------------- ------------

fizza operator

ameen ahmed mechanic

sanya clerk

13. Display all details from paylevel45 whose allowances ranges from 5000 to
10000(inclusive of both values)

SQL> select*from paylevel45 where allowance between 5000 and 10000;

PLEV PAY ALLOWANCE

---- -------- ----------

p002 22000 10000

p003 12000 6000

14. Display all details from paylevel45 whose allowances ranges from 5000 to
10000(exclusive of both values)
SQL> select*from paylevel45 where allowance >5000 and allowance <10000;

PLEV PAY ALLOWANCE


---- --------- -----------------
p003 12000 6000

5
15. Display all details from paylevel45 whose allowances not in the range from
5000 to 10000.
SQL> select*from paylevel45 where allowance not between 5000 and 10000;

PLEV PAY ALLOWANCE

---- ---------- ----------

p001 26000 12000

16. Display all details from worker45 whose name starts with r.

SQL> select*from worker45 where name like 'r%';

ECODE NAME DESIGN PLEV DOJ DOB

---------- --------------- ------------ ---- --------- ---------

11 Radhe shyam supervisor p001 13-SEP-04 23-AUG-81

17.Display all the details of worker45 whose name not starts with r.
SQL> select*from worker45 where name not like 'r%';

ECODE NAME DESIGN PLEV DOJ DOB

---------- --------------- ------------ ---- ----------- ---------

12 chander nath operator p002 22-FEB-81 12-JUL-87

13 fizza operator p003 14-JUN-10 14-OCT-83

14 ameen ahmed mechanic p004 21-AUG-06 13-MAR-84

15 sanya clerk p005 19-DEC-05 09-JUN-83

6
18. Display all the details of worker45 in descending order of designation.
SQL> select*from worker45 order by design desc;

ECODE NAME DESIGN PLEV DOJ DOB


---------- --------------- ------------ ---- --------- ---------

11 radhe shyam supervisor p001 13-SEP-04 23-AUG-81

12 chander nath operator p002 22-FEB-81 12-JUL-87

13 fizza operator p003 14-JUN-10 14-OCT-83

14 ameen ahmed mechanic p004 21-AUG-06 13-MAR-84

15 sanya clerk p005 19-DEC-05 09-JUN-83

19. To display the details of all worker45 in ascending order with name whose
ecode is more than 13
SQL> select*from worker45 where ecode>13 order by name;

ECODE NAME DESIGN PLEV DOJ DOB

-------- --------------- ------------ ---- --------- --------

14 ameen ahmed mechanic p004 21-AUG-06 13-MAR-84

15 sanya clerk p005 19-DEC-05 09-JUN-83.

7
20.Display the details of all workers in ascending order of name and
descending order of design.
SQL> select*from worker45 order by name asc,design desc;

ECODE NAME DESIGN PLEV DOJ DOB

---------- --------------- ------------ ---- ----------- ------------

14 ameen ahmed mechanic p004 21-AUG-06 13-MAR-84

12 chander nath operator p002 22-FEB-81 12-JUL-87

13 fizza operator p003 14-JUN-10 14-OCT-83

11 radhe shyam supervisor p001 13-SEP-04 23-AUG-81

15 sanya clerk p005 19-DEC-05 09-JUN-83

21.Display the total amount of allowance from paylevel45 whose pay is more
than 15000.
SQL> select sum(allowance) from paylevel45 where pay>15000;

SUM(ALLOWANCE)

--------------

22000

8
22.Display the number of records present in the table worker45 and
paylevel45
SQL> select count(*) from worker45;

COUNT(*)

----------

SQL> select count(*) from paylevel45;

COUNT(*)

----------

23.Display the maximum and the minimum pay of the worker45 in paylevel.
SQL> select max(pay),min(pay) from paylevel45;

MAX(PAY) MIN(PAY)

-------------- ----------

26000 12000

24 .Display the average allowances from the paylevel.


SQL> select avg(allowance) from paylevel45;

AVG(ALLOWANCE)

--------------------------

9333.3333

9
25. Display the number of designation of the worker that belongs to different
plevel.
SQL> select count(distinct design) from worker45;

COUNT(DISTINCTDESIGN)

--------------------------------------

26. Display the number of names present in the table worker.


SQL> select count(all name) from worker45;

COUNT(ALLNAME)

--------------------------

27. Display the number of plevel of each worker from each designation.
SQL> select count(plevel),plevel from worker45 group by plevel;

COUNT(PLEVEL) PLEV

----------------------- -----

1 p004

1 p001

1 p002

1 p005

1 p003

10
28. Display the number of designation of each worker whose count is more
than 1.
SQL> select count(design),design from worker45 group by design having count(design)>1;

COUNT(DESIGN) DESIGN

----------------------- ------------

2 operator

29. Display plevel,pay+allowance from the table paylevel45.


SQL> select plevel,pay+allowance from paylevel45;

PLEV PAY+ALLOWANCE

------- --------------------------

p001 38000

p002 32000

p003 18000

30. Display plevel,pay+allowance from the table paylevel45 by placing the


symbol $.
SQL> select plevel,pay+allowance,'$' from paylevel45;

PLEV PAY+ALLOWANCE '

---- --------------------------

p001 38000 $

p002 32000 $

p003 18000 $

11
31. Create a table workerinfo from table worker with the attributes doj,dob
and name .
SQL> create table workerinfo AS (select name, doj, dob from worker45 where name = chander
nath)

SQL> select*from workerinfo45;

NAME DOJ DOB

--------------- --------- ---------

chander nath 22-FEB-81 12-JUL-87

32. Add a column experience in the table worker45.


SQL> alter table worker45 add experience int;

Table altered.

33. Change the datatype of allowance in paylevel table to decimal.


alter table paylevel45 modify (allowance dec(7,2));

table modified.

12
34 . Insert the values for the column experience and display the table
worker45.
SQL> update worker45 set experience=10 where ecode=11;

1 row updated.

SQL> update worker45 set experience=12 where ecode=12;

1 row updated.

SQL> update worker45 set experience=11 where ecode=13;

1 row updated.

SQL> update worker45 set experience=9 where ecode=14;

1 row updated.

SQL> update worker45 set experience=10 where ecode=15;

1 row updated.

SQL> select* from worker45;

ECODE NAME DESIGN PLEV DOJ DOB EXPERIENCE

---------- --------------- ------------ --------- --------- --------- --------------

11 radhe shyam supervisor p001 13-SEP-04 23-AUG-81 10

12 chander nath operator p002 22-FEB-81 12-JUL-87 12

13 fizza operator p003 14-JUN-10 14-OCT-83 11

14 ameen ahmed mechanic p004 21-AUG-06 13-MAR-84 9

15 sanya clerk p005 19-DEC-05 09-JUN-83 15

13
35.To display the name and pay of your worker45 whose ecode is less than 13.
SQL> select name,pay from worker45 w,paylevel45 p where w.plevel=p.plevel and
w.ecode<13;

NAME PAY

--------------- ----------

radhe shyam 26000

chander nath 22000

36. Display the result by calculating 125*43.


SQL> select 125*43 from dual;

125*43

----------

5375

37. Display the lower case of the screen “WELCOME”.


SQL> select lower('WELCOME') from dual;

LOWER('

------------

Welcome

38.Display thanks in upperscreen.


SQL> select upper('thanks') from dual;

UPPER(

----------

THANKS

14
39.Delete the values of the table workerinfo whose names starts with c.
SQL> delete from workerinfo where name like 'c%';

1 row deleted.

40.Drop the table workerinfo.

SQL> drop table workerinfo;

Table dropped.

15

You might also like