SlideShare uma empresa Scribd logo
1 de 7
1) Create a table called Employ with the following structure.
Name Type
empno Number(6)
ename VARCHAR2(20)
Job VARCHAR2(20)
MGR NUMBER(4)
SAL NUMBER(7,2)
SQL> create table emp_tab(empno number(6), ename varchar2(20),
job varchar2(20), mgr number(4), sal number(7,2));
2)Add a column commission to the Employ table ‘deptno‘, numeric null allowed.
SQL> alter table emp_tab add (comm number,deptno number);
Table altered.
SQL> desc emp_tab;
Name Null? Type
----------------------------------------- -------- ------------
EMPNO NUMBER(6)
ENAME VARCHAR2(20)
JOB VARCHAR2(20)
MGR NUMBER(4)
SAL NUMBER(7,2)
COMM NUMBER
DEPTNO NUMBER
3)Modify the column width of the job field of Employ table.
SQL> alter table emp_tab modify (job varchar2(22));
Table altered.
SQL> desc emp_tab;
Name Null? Type
----------------------------------------- -------- ------------
EMPNO NUMBER(6)
ENAME VARCHAR2(20)
JOB VARCHAR2(22)
MGR NUMBER(4)
SAL NUMBER(7,2)
COMM NUMBER
DEPTNO NUMBER
4) Create dept table with the fields deptno,dname,loc.
SQL> create table dept_tab(deptno number(3),dname varchar2(15),loc
varchar2(15));
5) Add constraints to the Employ table that empno as the primary key
SQL> alter table emp_tab add primary key(empno);
Table altered.
SQL> desc emp_tab;
Name Null? Type
----------------------------------------- -------- -------------
EMPNO NOT NULL NUMBER(6)
ENAME VARCHAR2(20)
JOB VARCHAR2(22)
MGR NUMBER(4)
SAL NUMBER(7,2)
COMM NUMBER
DEPTNO NUMBER
7) Add constraints to the Department table that deptno as the primary key
SQL> alter table dept_tab add primary key(deptno);
Table altered.
SQL> desc dept_tab;
Name Null? Type
----------------------------------------- -------- -------------
DEPTNO NOT NULL NUMBER(3)
DNAME VARCHAR2(15)
LOC VARCHAR2(15)
8) Add deptno as the foreign key in Employ table.
SQL> alter table emp_tab add constraint foreign key references dept_tab(deptno);
9) Add constraints to the Employ table to check the empno value while entering
(i.e) empno > 100.
SQL> alter table emp_tab add check (empno>100);
10) Add columns Dob to the Employ table
SQL> alter table emp_tab add (dob date);
11) Add and drop a column bloodgroup to the Employ table
SQL> alter table emp_tab drop (key,blood_grp);
Table altered.
SQL> desc emp_tab;
Name Null? Type
----------------------------------------- -------- ------------
EMPNO NOT NULL NUMBER(6)
ENAME VARCHAR2(20)
JOB VARCHAR2(22)
MGR NUMBER(4)
SAL NUMBER(7,2)
COMM NUMBER
DEPTNO NUMBER
DOB DATE
12) Insert the any three records in the Department table as shown below and use
rollback? Check the result?
SQL> insert into dept_tab values(&deptno,'&dname','&loc');
Enter value for deptno: 111
Enter value for dname: Finance
Enter value for loc: unit 1
old 1: insert into dept_tab values(&deptno,'&dname','&loc')
new 1: insert into dept_tab values(111,'Finance','unit 1')
1 row created.
SQL> /
Enter value for deptno: 222
Enter value for dname: Admin
Enter value for loc: unit 1
old 1: insert into dept_tab values(&deptno,'&dname','&loc')
new 1: insert into dept_tab values(222,'Admin','unit 1')
1 row created.
SQL> /
Enter value for deptno: 333
Enter value for dname: Production
Enter value for loc: unit 2
old 1: insert into dept_tab values(&deptno,'&dname','&loc')
new 1: insert into dept_tab values(333,'Production','unit 2
1 row created.
SQL> /
Enter value for deptno: 444
Enter value for dname: Welding
Enter value for loc: unit 2
old 1: insert into dept_tab values(&deptno,'&dname','&loc')
new 1: insert into dept_tab values(444,'Welding','unit 2')
1 row created.
SQL> /
Enter value for deptno: 555
Enter value for dname: Shipping
Enter value for loc: unit 3
old 1: insert into dept_tab values(&deptno,'&dname','&loc')
new 1: insert into dept_tab values(555,'Shipping','unit 3')
1 row created.
SQL> select * from dept_tab;
DEPTNO DNAME LOC
---------- --------------- ---------------
111 Finance unit 1
222 Admin unit 1
333 Production unit 2
444 Welding unit 2
555 Shipping unit 3
SQL> roll back;
Rollback complete.
SQL> select * from dept_tab;
no rows selected
13) Insert the any three records in the dept table shown below and use commit?
Check the result?
SQL> insert into dept_tab values(&deptno,'&dname','&loc');
Enter value for deptno: 111
Enter value for dname: Finance
Enter value for loc: Unit 1
old 1: insert into dept_tab values(&deptno,'&dname','&loc')
new 1: insert into dept_tab values(111,'Finance','Unit 1')
1 row created.
SQL> /
Enter value for deptno: 222
Enter value for dname: Admin
Enter value for loc: Unit 1
old 1: insert into dept_tab values(&deptno,'&dname','&loc')
new 1: insert into dept_tab values(222,'Admin','Unit 1')
1 row created.
SQL> /
Enter value for deptno: 333
Enter value for dname: Production
Enter value for loc: Unit 2
old 1: insert into dept_tab values(&deptno,'&dname','&loc')
new 1: insert into dept_tab values(333,'Production','Unit 2')
1 row created.
SQL> /
Enter value for deptno: 444
Enter value for dname: Welding
Enter value for loc: Unit 2
old 1: insert into dept_tab values(&deptno,'&dname','&loc')
new 1: insert into dept_tab values(444,'Welding','Unit 2')
1 row created.
SQL> /
Enter value for deptno: 555
Enter value for dname: Packing
Enter value for loc: Unit 3
old 1: insert into dept_tab values(&deptno,'&dname','&loc')
new 1: insert into dept_tab values(555,'Packing','Unit 3')
1 row created.
SQL> /
Enter value for deptno: 666
Enter value for dname: Shipping
Enter value for loc: Unit 3
old 1: insert into dept_tab values(&deptno,'&dname','&loc')
new 1: insert into dept_tab values(666,'Shipping','Unit 3')
1 row created.
SQL> commit;
Commit complete.
SQL> select * from dept_tab;
DEPTNO DNAME LOC
---------- --------------- ---------------
111 Finance Unit 1
222 Admin Unit 1
333 Production Unit 2
444 Welding Unit 2
555 Packing Unit 3
666 Shipping Unit 3
6 rows selected.
SQL> roll back;
Rollback complete.
SQL> select * from dept_tab;
DEPTNO DNAME LOC
---------- --------------- ---------------
111 Finance Unit 1
222 Admin Unit 1
333 Production Unit 2
444 Welding Unit 2
555 Packing Unit 3
666 Shipping Unit 3
6 rows selected.
14) Delete one row with deptno=333 from dept table and display the table. Now
use undo the changes by using appropriate command.
SQL> delete from dept_tab where deptno=333;
1 row deleted.
SQL> select * from dept_tab;
DEPTNO DNAME LOC
---------- --------------- ---------------
111 Finance Unit 1
222 Admin Unit 1
444 Welding Unit 2
555 Packing Unit 3
666 Shipping Unit 3
SQL> roll back;
Rollback complete.
SQL> select * from dept_tab;
DEPTNO DNAME LOC
---------- --------------- ---------------
111 Finance Unit 1
222 Admin Unit 1
333 Production Unit 2
444 Welding Unit 2
555 Packing Unit 3
666 Shipping Unit 3
6 rows selected.
15) Insert rows into Employ table
SQL> insert into emp_tab values(&empno,'&ename','&job',&mgr,&sal,&comm,&deptno,'
&dob');
SQL> /
Enter value for empno: 121
Enter value for ename: Chang
Enter value for job: Analyst
Enter value for mgr: 5
Enter value for sal: 45000
Enter value for comm: 500
Enter value for deptno: 333
Enter value for dob: 12-Jan-1990
old 1: insert into emp_tab values(&empno,'&ename','&job',&mgr,&sal,&comm,&dept
no,'&dob')
new 1: insert into emp_tab values(121,'Chang','Analyst',5,45000,500,333,'12-Ja
n-1990')
1 row created.
SQL> /
Enter value for empno: 122
Enter value for ename: Marroou
Enter value for job: Auditor
Enter value for mgr: 131
Enter value for sal: 67000
Enter value for comm: 111
Enter value for deptno: 111
Enter value for dob: 23-Mar-1981
old 1: insert into emp_tab values(&empno,'&ename','&job',&mgr,&sal,&comm,&dept
no,'&dob')
new 1: insert into emp_tab values(122,'Marroou','Auditor',131,67000,111,111,'2
3-Mar-1981')
1 row created.
SQL> /
Enter value for empno: 131
Enter value for ename: Sheeshoo
Enter value for job: Manager
Enter value for mgr: 999
Enter value for sal: 90000
Enter value for comm: 700
Enter value for deptno: 111
Enter value for dob: 13-May-1972
old 1: insert into emp_tab values(&empno,'&ename','&job',&mgr,&sal,&comm,&dept
no,'&dob')
new 1: insert into emp_tab values(131,'Sheeshoo','Manager',999,90000,700,111,'
13-May-1972')
1 row created.
SQL> /
Enter value for empno: 132
Enter value for ename: Kiyow
Enter value for job: Manager
Enter value for mgr: 999
Enter value for sal: 90000
Enter value for comm: 700
Enter value for deptno: 333
Enter value for dob: 25-Jul-1978
old 1: insert into emp_tab values(&empno,'&ename','&job',&mgr,&sal,&comm,&dept
no,'&dob')
new 1: insert into emp_tab values(132,'Kiyow','Manager',999,90000,700,333,'25-
Jul-1978')
1 row created.
SQL> /
Enter value for empno: 999
Enter value for ename: Jangchee
Enter value for job: BusinesHead
Enter value for mgr: 0
Enter value for sal: 99999
Enter value for comm: 0
Enter value for deptno: 222
Enter value for dob: 30-Sep-1969
old 1: insert into emp_tab values(&empno,'&ename','&job',&mgr,&sal,&comm,&dept
no,'&dob')
new 1: insert into emp_tab values(999,'Jangchee','BusinesHead',0,99999,0,222,'
30-Sep-1969')
1 row created.
SQL> select * from emp_tab;
EMPNO ENAME JOB MGR SAL
---------- -------------------- ---------------------- ---------- ----------
COMM DEPTNO DOB
---------- ---------- ---------
121 Chang Analyst 132 45000
500 333 12-JAN-90
122 Marroou Auditor 131 67000
111 111 23-MAR-81
131 Sheeshoo Manager 999 90000
700 111 13-MAY-72
EMPNO ENAME JOB MGR SAL
---------- -------------------- ---------------------- ---------- ----------
COMM DEPTNO DOB
---------- ---------- ---------
132 Kiyow Manager 999 90000
700 333 25-JUL-78
999 Jangchee BusinesHead 0 99999
0 222 30-SEP-69
16) Issue a query to find all the employees who work in the same job as Sheeshoo
SQL> select * from emp_tab where job=(select job from emp_tab where ename='Shees
hoo');
EMPNO ENAME JOB MGR SAL
---------- -------------------- ---------------------- ---------- ----------
COMM DEPTNO DOB
---------- ---------- ---------
131 Sheeshoo Manager 999 90000
700 111 13-MAY-72
132 Kiyow Manager 999 90000
700 333 25-JUL-78
17) Issue a query to display information about employees who earn more than any
employee in dept 333.
SQL> select * from emp_tab where sal=(select max(sal) from emp_tab where deptno=
333) and deptno=333;
EMPNO ENAME JOB MGR SAL
---------- -------------------- ---------------------- ---------- ----------
COMM DEPTNO DOB
---------- ---------- ---------
132 Kiyow Manager 999 90000
700 333 25-JUL-78

Mais conteúdo relacionado

Mais procurados

Oracle ERP Personalization for control master items list
Oracle ERP Personalization for control master items listOracle ERP Personalization for control master items list
Oracle ERP Personalization for control master items listAhmed Elshayeb
 
Python sqlite3 - flask
Python   sqlite3 - flaskPython   sqlite3 - flask
Python sqlite3 - flaskEueung Mulyana
 
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyBrian Aker
 
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий КуриловАсинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий КуриловYandex
 
Gearman, from the worker's perspective
Gearman, from the worker's perspectiveGearman, from the worker's perspective
Gearman, from the worker's perspectiveBrian Aker
 
Quick reference for HBase shell commands
Quick reference for HBase shell commandsQuick reference for HBase shell commands
Quick reference for HBase shell commandsRajkumar Asohan, PMP
 
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 2. Porting Oracle UDF and OptimizationPgDay.Seoul
 

Mais procurados (19)

Les00 Intoduction
Les00 IntoductionLes00 Intoduction
Les00 Intoduction
 
Les11
Les11Les11
Les11
 
Oracle ERP Personalization for control master items list
Oracle ERP Personalization for control master items listOracle ERP Personalization for control master items list
Oracle ERP Personalization for control master items list
 
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Les01 Writing Basic Sql Statements
 
Les12
Les12Les12
Les12
 
Les02
Les02Les02
Les02
 
ZFINDALLZPROGAM
ZFINDALLZPROGAMZFINDALLZPROGAM
ZFINDALLZPROGAM
 
Les10
Les10Les10
Les10
 
Les06 Subqueries
Les06 SubqueriesLes06 Subqueries
Les06 Subqueries
 
my_project
my_projectmy_project
my_project
 
Les04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple TableLes04 Displaying Data From Multiple Table
Les04 Displaying Data From Multiple Table
 
Python sqlite3 - flask
Python   sqlite3 - flaskPython   sqlite3 - flask
Python sqlite3 - flask
 
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copy
 
Les05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group FunctionLes05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group Function
 
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий КуриловАсинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
 
Gearman, from the worker's perspective
Gearman, from the worker's perspectiveGearman, from the worker's perspective
Gearman, from the worker's perspective
 
Quick reference for HBase shell commands
Quick reference for HBase shell commandsQuick reference for HBase shell commands
Quick reference for HBase shell commands
 
Les02 Restricting And Sorting Data
Les02 Restricting And Sorting DataLes02 Restricting And Sorting Data
Les02 Restricting And Sorting Data
 
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
 

Semelhante a 4sem dbms(1)

SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9Umair Amjad
 
Database management system file
Database management system fileDatabase management system file
Database management system fileAnkit Dixit
 
Les09[1]Manipulating Data
Les09[1]Manipulating DataLes09[1]Manipulating Data
Les09[1]Manipulating Datasiavosh kaviani
 
Optimizer in oracle 11g by wwf from ebay COC
Optimizer in oracle 11g by wwf from ebay COCOptimizer in oracle 11g by wwf from ebay COC
Optimizer in oracle 11g by wwf from ebay COCLouis liu
 
Queries assignment udf_and_triggers
Queries assignment udf_and_triggersQueries assignment udf_and_triggers
Queries assignment udf_and_triggersPriya Sharma
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application DevelopmentSaurabh K. Gupta
 
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxMSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxgilpinleeanna
 
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersConnor McDonald
 
Complex Queries using MYSQL00123211.pptx
Complex Queries using MYSQL00123211.pptxComplex Queries using MYSQL00123211.pptx
Complex Queries using MYSQL00123211.pptxmetriohanzel
 
Oracle 11g new features for developers
Oracle 11g new features for developersOracle 11g new features for developers
Oracle 11g new features for developersScott Wesley
 
Advance Features In Procedues And Triggers
Advance Features In Procedues And TriggersAdvance Features In Procedues And Triggers
Advance Features In Procedues And TriggersKeshav Murthy
 
Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricksYanli Liu
 

Semelhante a 4sem dbms(1) (20)

SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9
 
Database management system file
Database management system fileDatabase management system file
Database management system file
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
Les09[1]Manipulating Data
Les09[1]Manipulating DataLes09[1]Manipulating Data
Les09[1]Manipulating Data
 
Select To Order By
Select  To  Order BySelect  To  Order By
Select To Order By
 
Optimizer in oracle 11g by wwf from ebay COC
Optimizer in oracle 11g by wwf from ebay COCOptimizer in oracle 11g by wwf from ebay COC
Optimizer in oracle 11g by wwf from ebay COC
 
DOODB_LAB.pptx
DOODB_LAB.pptxDOODB_LAB.pptx
DOODB_LAB.pptx
 
Queries assignment udf_and_triggers
Queries assignment udf_and_triggersQueries assignment udf_and_triggers
Queries assignment udf_and_triggers
 
Oracle Database 12c Application Development
Oracle Database 12c Application DevelopmentOracle Database 12c Application Development
Oracle Database 12c Application Development
 
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxMSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
 
OpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer DisastersOpenWorld 2018 - Common Application Developer Disasters
OpenWorld 2018 - Common Application Developer Disasters
 
Sql 3
Sql 3Sql 3
Sql 3
 
Complex Queries using MYSQL00123211.pptx
Complex Queries using MYSQL00123211.pptxComplex Queries using MYSQL00123211.pptx
Complex Queries using MYSQL00123211.pptx
 
My SQL.pptx
My SQL.pptxMy SQL.pptx
My SQL.pptx
 
Oracle 11g new features for developers
Oracle 11g new features for developersOracle 11g new features for developers
Oracle 11g new features for developers
 
Dbms lab Manual
Dbms lab ManualDbms lab Manual
Dbms lab Manual
 
Advance Features In Procedues And Triggers
Advance Features In Procedues And TriggersAdvance Features In Procedues And Triggers
Advance Features In Procedues And Triggers
 
Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricks
 
SQL (1).pptx
SQL (1).pptxSQL (1).pptx
SQL (1).pptx
 
Oracle
OracleOracle
Oracle
 

4sem dbms(1)

  • 1. 1) Create a table called Employ with the following structure. Name Type empno Number(6) ename VARCHAR2(20) Job VARCHAR2(20) MGR NUMBER(4) SAL NUMBER(7,2) SQL> create table emp_tab(empno number(6), ename varchar2(20), job varchar2(20), mgr number(4), sal number(7,2)); 2)Add a column commission to the Employ table ‘deptno‘, numeric null allowed. SQL> alter table emp_tab add (comm number,deptno number); Table altered. SQL> desc emp_tab; Name Null? Type ----------------------------------------- -------- ------------ EMPNO NUMBER(6) ENAME VARCHAR2(20) JOB VARCHAR2(20) MGR NUMBER(4) SAL NUMBER(7,2) COMM NUMBER DEPTNO NUMBER 3)Modify the column width of the job field of Employ table. SQL> alter table emp_tab modify (job varchar2(22)); Table altered. SQL> desc emp_tab; Name Null? Type ----------------------------------------- -------- ------------ EMPNO NUMBER(6) ENAME VARCHAR2(20) JOB VARCHAR2(22) MGR NUMBER(4) SAL NUMBER(7,2) COMM NUMBER DEPTNO NUMBER 4) Create dept table with the fields deptno,dname,loc. SQL> create table dept_tab(deptno number(3),dname varchar2(15),loc varchar2(15)); 5) Add constraints to the Employ table that empno as the primary key SQL> alter table emp_tab add primary key(empno); Table altered. SQL> desc emp_tab; Name Null? Type ----------------------------------------- -------- -------------
  • 2. EMPNO NOT NULL NUMBER(6) ENAME VARCHAR2(20) JOB VARCHAR2(22) MGR NUMBER(4) SAL NUMBER(7,2) COMM NUMBER DEPTNO NUMBER 7) Add constraints to the Department table that deptno as the primary key SQL> alter table dept_tab add primary key(deptno); Table altered. SQL> desc dept_tab; Name Null? Type ----------------------------------------- -------- ------------- DEPTNO NOT NULL NUMBER(3) DNAME VARCHAR2(15) LOC VARCHAR2(15) 8) Add deptno as the foreign key in Employ table. SQL> alter table emp_tab add constraint foreign key references dept_tab(deptno); 9) Add constraints to the Employ table to check the empno value while entering (i.e) empno > 100. SQL> alter table emp_tab add check (empno>100); 10) Add columns Dob to the Employ table SQL> alter table emp_tab add (dob date); 11) Add and drop a column bloodgroup to the Employ table SQL> alter table emp_tab drop (key,blood_grp); Table altered. SQL> desc emp_tab; Name Null? Type ----------------------------------------- -------- ------------ EMPNO NOT NULL NUMBER(6) ENAME VARCHAR2(20) JOB VARCHAR2(22) MGR NUMBER(4) SAL NUMBER(7,2) COMM NUMBER DEPTNO NUMBER DOB DATE 12) Insert the any three records in the Department table as shown below and use rollback? Check the result? SQL> insert into dept_tab values(&deptno,'&dname','&loc'); Enter value for deptno: 111 Enter value for dname: Finance Enter value for loc: unit 1 old 1: insert into dept_tab values(&deptno,'&dname','&loc') new 1: insert into dept_tab values(111,'Finance','unit 1')
  • 3. 1 row created. SQL> / Enter value for deptno: 222 Enter value for dname: Admin Enter value for loc: unit 1 old 1: insert into dept_tab values(&deptno,'&dname','&loc') new 1: insert into dept_tab values(222,'Admin','unit 1') 1 row created. SQL> / Enter value for deptno: 333 Enter value for dname: Production Enter value for loc: unit 2 old 1: insert into dept_tab values(&deptno,'&dname','&loc') new 1: insert into dept_tab values(333,'Production','unit 2 1 row created. SQL> / Enter value for deptno: 444 Enter value for dname: Welding Enter value for loc: unit 2 old 1: insert into dept_tab values(&deptno,'&dname','&loc') new 1: insert into dept_tab values(444,'Welding','unit 2') 1 row created. SQL> / Enter value for deptno: 555 Enter value for dname: Shipping Enter value for loc: unit 3 old 1: insert into dept_tab values(&deptno,'&dname','&loc') new 1: insert into dept_tab values(555,'Shipping','unit 3') 1 row created. SQL> select * from dept_tab; DEPTNO DNAME LOC ---------- --------------- --------------- 111 Finance unit 1 222 Admin unit 1 333 Production unit 2 444 Welding unit 2 555 Shipping unit 3 SQL> roll back; Rollback complete. SQL> select * from dept_tab; no rows selected 13) Insert the any three records in the dept table shown below and use commit? Check the result? SQL> insert into dept_tab values(&deptno,'&dname','&loc'); Enter value for deptno: 111 Enter value for dname: Finance Enter value for loc: Unit 1 old 1: insert into dept_tab values(&deptno,'&dname','&loc') new 1: insert into dept_tab values(111,'Finance','Unit 1')
  • 4. 1 row created. SQL> / Enter value for deptno: 222 Enter value for dname: Admin Enter value for loc: Unit 1 old 1: insert into dept_tab values(&deptno,'&dname','&loc') new 1: insert into dept_tab values(222,'Admin','Unit 1') 1 row created. SQL> / Enter value for deptno: 333 Enter value for dname: Production Enter value for loc: Unit 2 old 1: insert into dept_tab values(&deptno,'&dname','&loc') new 1: insert into dept_tab values(333,'Production','Unit 2') 1 row created. SQL> / Enter value for deptno: 444 Enter value for dname: Welding Enter value for loc: Unit 2 old 1: insert into dept_tab values(&deptno,'&dname','&loc') new 1: insert into dept_tab values(444,'Welding','Unit 2') 1 row created. SQL> / Enter value for deptno: 555 Enter value for dname: Packing Enter value for loc: Unit 3 old 1: insert into dept_tab values(&deptno,'&dname','&loc') new 1: insert into dept_tab values(555,'Packing','Unit 3') 1 row created. SQL> / Enter value for deptno: 666 Enter value for dname: Shipping Enter value for loc: Unit 3 old 1: insert into dept_tab values(&deptno,'&dname','&loc') new 1: insert into dept_tab values(666,'Shipping','Unit 3') 1 row created. SQL> commit; Commit complete. SQL> select * from dept_tab; DEPTNO DNAME LOC ---------- --------------- --------------- 111 Finance Unit 1 222 Admin Unit 1 333 Production Unit 2 444 Welding Unit 2 555 Packing Unit 3 666 Shipping Unit 3 6 rows selected.
  • 5. SQL> roll back; Rollback complete. SQL> select * from dept_tab; DEPTNO DNAME LOC ---------- --------------- --------------- 111 Finance Unit 1 222 Admin Unit 1 333 Production Unit 2 444 Welding Unit 2 555 Packing Unit 3 666 Shipping Unit 3 6 rows selected. 14) Delete one row with deptno=333 from dept table and display the table. Now use undo the changes by using appropriate command. SQL> delete from dept_tab where deptno=333; 1 row deleted. SQL> select * from dept_tab; DEPTNO DNAME LOC ---------- --------------- --------------- 111 Finance Unit 1 222 Admin Unit 1 444 Welding Unit 2 555 Packing Unit 3 666 Shipping Unit 3 SQL> roll back; Rollback complete. SQL> select * from dept_tab; DEPTNO DNAME LOC ---------- --------------- --------------- 111 Finance Unit 1 222 Admin Unit 1 333 Production Unit 2 444 Welding Unit 2 555 Packing Unit 3 666 Shipping Unit 3 6 rows selected. 15) Insert rows into Employ table SQL> insert into emp_tab values(&empno,'&ename','&job',&mgr,&sal,&comm,&deptno,' &dob'); SQL> / Enter value for empno: 121 Enter value for ename: Chang Enter value for job: Analyst Enter value for mgr: 5 Enter value for sal: 45000 Enter value for comm: 500 Enter value for deptno: 333 Enter value for dob: 12-Jan-1990 old 1: insert into emp_tab values(&empno,'&ename','&job',&mgr,&sal,&comm,&dept no,'&dob')
  • 6. new 1: insert into emp_tab values(121,'Chang','Analyst',5,45000,500,333,'12-Ja n-1990') 1 row created. SQL> / Enter value for empno: 122 Enter value for ename: Marroou Enter value for job: Auditor Enter value for mgr: 131 Enter value for sal: 67000 Enter value for comm: 111 Enter value for deptno: 111 Enter value for dob: 23-Mar-1981 old 1: insert into emp_tab values(&empno,'&ename','&job',&mgr,&sal,&comm,&dept no,'&dob') new 1: insert into emp_tab values(122,'Marroou','Auditor',131,67000,111,111,'2 3-Mar-1981') 1 row created. SQL> / Enter value for empno: 131 Enter value for ename: Sheeshoo Enter value for job: Manager Enter value for mgr: 999 Enter value for sal: 90000 Enter value for comm: 700 Enter value for deptno: 111 Enter value for dob: 13-May-1972 old 1: insert into emp_tab values(&empno,'&ename','&job',&mgr,&sal,&comm,&dept no,'&dob') new 1: insert into emp_tab values(131,'Sheeshoo','Manager',999,90000,700,111,' 13-May-1972') 1 row created. SQL> / Enter value for empno: 132 Enter value for ename: Kiyow Enter value for job: Manager Enter value for mgr: 999 Enter value for sal: 90000 Enter value for comm: 700 Enter value for deptno: 333 Enter value for dob: 25-Jul-1978 old 1: insert into emp_tab values(&empno,'&ename','&job',&mgr,&sal,&comm,&dept no,'&dob') new 1: insert into emp_tab values(132,'Kiyow','Manager',999,90000,700,333,'25- Jul-1978') 1 row created. SQL> / Enter value for empno: 999 Enter value for ename: Jangchee Enter value for job: BusinesHead Enter value for mgr: 0 Enter value for sal: 99999 Enter value for comm: 0 Enter value for deptno: 222 Enter value for dob: 30-Sep-1969 old 1: insert into emp_tab values(&empno,'&ename','&job',&mgr,&sal,&comm,&dept no,'&dob')
  • 7. new 1: insert into emp_tab values(999,'Jangchee','BusinesHead',0,99999,0,222,' 30-Sep-1969') 1 row created. SQL> select * from emp_tab; EMPNO ENAME JOB MGR SAL ---------- -------------------- ---------------------- ---------- ---------- COMM DEPTNO DOB ---------- ---------- --------- 121 Chang Analyst 132 45000 500 333 12-JAN-90 122 Marroou Auditor 131 67000 111 111 23-MAR-81 131 Sheeshoo Manager 999 90000 700 111 13-MAY-72 EMPNO ENAME JOB MGR SAL ---------- -------------------- ---------------------- ---------- ---------- COMM DEPTNO DOB ---------- ---------- --------- 132 Kiyow Manager 999 90000 700 333 25-JUL-78 999 Jangchee BusinesHead 0 99999 0 222 30-SEP-69 16) Issue a query to find all the employees who work in the same job as Sheeshoo SQL> select * from emp_tab where job=(select job from emp_tab where ename='Shees hoo'); EMPNO ENAME JOB MGR SAL ---------- -------------------- ---------------------- ---------- ---------- COMM DEPTNO DOB ---------- ---------- --------- 131 Sheeshoo Manager 999 90000 700 111 13-MAY-72 132 Kiyow Manager 999 90000 700 333 25-JUL-78 17) Issue a query to display information about employees who earn more than any employee in dept 333. SQL> select * from emp_tab where sal=(select max(sal) from emp_tab where deptno= 333) and deptno=333; EMPNO ENAME JOB MGR SAL ---------- -------------------- ---------------------- ---------- ---------- COMM DEPTNO DOB ---------- ---------- --------- 132 Kiyow Manager 999 90000 700 333 25-JUL-78