SlideShare a Scribd company logo
PreparedBy JAVATECH Search us in The World
Chapter DiscussionAbout Database Object, SubQuery, Joining ( 3 chapters inone class)
Database has few objects. They are
1. Table : Basic unit of storage which represented as rows and columns format.
2. View : It is logical subsets of data from more than one table.
3. Sequence : It is used to generate Unique integer number.
4. Synonym : It is an ulternate name for other database objects.
5. Index : Oracle server used index to faster access the rows using pointer.
View : It is logical subsets of data from more than one table. There are two types of view.
1. Simple view
2. Complex View
Why we use view
1. To restrict Data access : View doesnot allows to access all columns from table. It is created selected
columns only. Importants columns hides from other user.
2. Make complex query easy : You don’t need everytime specify join command. Only write once complex
commnd and make view. Then only access that view.
Simple View
The view which consists of only one tble is called simple view. The DML operation can perform with
this view. If you want restrict DML operation you can write WITH READ ONLY statement to avoid DML
operation
Complex View
The view which consists of more than one table is called Complex View. It restricts DML operation.
ROLL NAME DOB MARK
1 A 12-JAN-1990 500
2 B 16-JUN-1992 408
3 C 19-JUL-2000 557
4 D 30-MAY-1997 300
5 E 22-SEP-2000 490
Create View v1 as select roll,mark from student;
Above command create view name v1 consists of two column;
You can define your own column inside view
Create or replace view v1(MyRoll,MyMark) as select roll,mark from student;
Above command updated your view (because i write replace command) with MyRoll and MyMark column.
If you write select statement
Select * from v1;
It display like
MyRoll MyMark
1 500
2 408
3 557
4 300
5 490
You can update view
Update set mark=900 where roll=1;
After select from v1
MyRoll MyMark
1 900
2 408
3 557
4 300
5 490
Same also updated in Table
Select * from student;
ROLL NAME DOB MARK
1 A 12-JAN-1990 900
2 B 16-JUN-1992 408
3 C 19-JUL-2000 557
4 D 30-MAY-1997 300
5 E 22-SEP-2000 490
If you want to restrict DML operation in view then use WITH READ ONLY
E.g.
Create View v2 as select roll,mark from student where roll=2 WITH READ ONLY;
Then when you try to update view v2 whose roll is two it display arror.
Complex view
The view which consists of more than one table is called Complex table. Here DML command is
restriction
See the E.g
Create view v3(MyRoll,MyName,MyDept,Price) as Select stud1.roll,stud1.name,dept.name,dept.price from
stud,dept where stud.roll=dept.roll;
Here you can see view v3 is (MyRoll,MyName,MyDept,Price) is created. It is consists of 4 columns.
Sequence
Sequence is used to create to generate unique integer values. Declaraton of Synnym
Create sequence sequence_name : sequence name
Increment by n - sequence increment by n, specify the interval between sequence number
Strart with n – n is specified by the starting value of sequence
Max value n – n specified where sequence number will be start.
Min value n - n specify the minimum sequence no
Cycle / nocycle – after reach at max valueit will be recycled. Means again starts value from minimum no.
Cache n/ nocace – how many number oracle can allocate memory to store in memory. Numbers are faster
access from memory.
See how created ?
Create sequence s1 //sequence name is s1
Increment by 1 //sequence is incremented by 1
Start with 3 //sequence start value
MaxValue 30 //sequence will stop as it reached 30
MinValue 2 //After reached 30 next time it start from 2. Not again from start value. And minvalue
//should less than start value.
Cycle //cycle means value will be recycled after reach max value.
Error:ORA-04013 Number to Cache must be less than one cycle. So max value should specify 22 or above.
Default cache is 21.
Sequence Created.
To check sequence
Select s1.nextval from dual;
Select s1.currvalue from dual;
To verify user sequence from user_sequence data dictionary
SELECT sequence_name, min_value, max_value, increment_by, last_number FROM user_sequences;
You can also write
Insert into stud values(s1.nextval,’aa’,789);
To drop sequence
Drop sequence sequence_name;
Drop sequence s1;
Synonym
It is called alternate name for table.
E.g.
Create synonym sn for student_sce_dept;
Then instead of write big table name we use it through small name sn.
E.g. select * from sn; it display data from student_sce_dept.
To drop synonym
Drop synonym sn;
Index
Is used by the Oracle server to speed up the retrieval of rows by using a pointer
two types index
Automatically: when we declare primary key or unique key.
Manually: Users can create nonunique indexes on columns to speed up access to the rows.
CREATE INDEX emp_last_name_idx ON employees(last_name);
Index created.
SUB QUERY
It is called inner query. The query which is exists in another query is called inner query. It is also called nested
query.
Features
1. It is enclosed with parenthesis
2. It is written right side of outer query.
3. Inner query first executed then outer query executed.
4. Outer Query executed after result return from inner query.
Two types of inner query
Sometimes inner query returns two types result. First single result second multiple row result. Based upon this
It is two types.
1. Single row return inner query
2. Multi row return inner query
E.g.
Select name from student where mark<(select mark from student where name=’Ramesh’);
Right side is called inner query. First we should know what is mark of Ramesh. Then we select mark those are
below ramesh mark. In bold and underlined mark is called inner query.
Single row returns inner query operator
1. =
2. >
3. <
4. >=
5. <=
6. <>
Multiple rows returns inner queries
1. IN : If outer query matched any value from IN operator then it returns result.
2. ANY : <ANY means Less than the maximum. >ANY means more than the minimum.=ANY is equivalent
to IN
3. ALL : <ALL means less than the minimum and >ALL means more than the maximum.
Select name from student where mark in (300,700,800);
Or
Select name from student where mark in(select mark from student where mark<900);
JOIN command
Join command is used to return query more than one table.
Prior to Join Oracle8i or Prior
1. Cartesian Join
2. Equi-Join same as simple join same as inner join
3. Non-Equi Join
4. Outer Join
5. Self Join
Oracle 9i or Next
1. Cross Join
2. Natural Join
3. Using clause
4. ON clause
5. Full or two sided outer join
CartesianJoin
When we specify join command invalid or ommit then result of cartesian join will be produced
between two table.
E.g.
Selet roll,name,mark,branch from stud,dept;
Here stud has 5 rows and dept has 4 rows. Then total 5*4=20 rows will be ceated.
Equi Join:
It is based upon equality of two values of same column of two different tables. It use the (=) operator.
Select stud.roll,name,mark,branch from stud,dept where stud.roll=dept.roll;
It display roll,name from stud table mark branch from dept table those roll are same to both table. (=)
Table alias
Select s.roll,s.name ,d.mark,d.branch from stud s,dept d where s.roll=d.roll;
Above we specify alias name for both table s & d. S is alternate name for stud table and D is alternate
name for Dept table. Advantages No need to write tablename repeatedly. Only use the shortcut name.
For faster write the query.
Ambiguity inColumn.
Here roll is common column for stud and dept table. When we write query
select roll,name,mark,branch from stud,dept .............
Oracle server will be confuse to take about roll. Because it is common. So we specify which table roll
column we want to display. Modified query is
Select stud.roll , name, mark branch from stud,dept where stud.roll=dept.roll;
Non Equi Join
The operator which are used other than (=) is called Non Equi Join. Operators are used
1. >
2. <
3. <>
4. Between
Select s.name,d.mark from stud s,dept d where s.mark between d.high_mark and g.low_mark;
Left outer Join / Right Outer Join / Full Outer Join
Outer Join-It is an extension of inner join. It returns rows that are matched to both tables. And also returns
those are not matched to another table.
It returns the rows those are missed in join condition. Outer join symbol is (+) sign
e.roll(+)=d.roll //left outer join It returns the rows that are matched to both table except return rows those
that are not matched to the first table.
e.roll=d.roll(+) //right outer join it returns the rows that are matched to both table except returns the rows
that are not matched to the second table.
Full outer join: The join between two tables, that returns the result of an inner join as well as the result of left
outer join and return result of right join is a full outer join.
Full outer join
select name,mark from join7,join8 where join7.roll(+)=join8.roll union all select name,mark from join7,join8
where join7.roll=join8.roll(+)
Right Outer Join
select name,mark from join7,join8 where join7.roll=join8.roll(+);
Left Outer Join
select name,mark from join7,join8 where join7.roll(+)=join8.roll;
Self Join
From Stud d Natural Join Dept d; automatically choose same column name by oracle.
From stud s join dept d using (roll) // using clause is used to specify column name by user choice in join
condition
From stud s join dept d on(s.roll=d.my_roll) on clause is used to specify that have different column name.
Here roll & my_roll is not matched
Left outer join
select s.name,d.mark from join7 s left outer join join8 d on (s.roll=d.roll)
Right outer join
select s.name,d.mark from join7 s right outer join join8 d on (s.roll=d.roll)
Full outer join
select s.name,d.mark from join7 s full outer join join8 d on (s.roll=d.roll)
Prepared By JAVATECH Search us in The World
ASSIGNMENT ON DATABASE OBJECT,SUB-QUERY AND JOIN COMMAND
STUDENT
STU_ROLL NAME DOB MARK BRANCH SECTION
AMIT 13/05/2010 600 SCE IT-1
AJAY 25/09/2009 550 IT IT-2
ROHIT 15/12/2008 450 IT CS-1
MUKESH 02/11/2007 390 SCE CS-2
JOHN 30/03/2005 400 IT CS-3
FACULTY
FACULTY_ID FAC_NAME STU_ROLL FAC_SUBJECT CLASS_ROOM CLASS_DATE_TIME
JOSEPH JAVA C1
STEPHEN C++ C2
RICHARDSON DOTNET C3
JAMES PHP C4
AKS ORACLE C5
TIPS:- CLASS_DATE_TIME DATATYPE IS TIMESTAMP(2) - TIMESTAMP IS USED FOR TO SPECIFY TIME. 2
MEANS AFTER SECOND VALUE FRACTION VALUE WON’T DISPLAY. ONLY TWO DIGIT SECOND DISPLAY.
INSERT INTO TABLE VALUES(TO_DATE(’12-JAN-2001 13:34:56’,’DD-MON-YY HH24:MI:SS’));
1. Enter exact data into student table. But roll should insert using sequence, it should start from 1 and
increment by 1.[total 5 records]
2. Enter exact data into faculty table. But faculty id should insert using sequence, it should start from 1
and increment by 3[total 5 records]. E.g. 1, 4, 7, 10, 13 Also enter exact student roll into faculty table
from referencing student table by using sequence but it should be increment by 2. E.g. 1, 3, 5, 7, 9
[total 5 records]
3. Waq to display sequence name, minimum value, maximum value from all created sequences.
4. Waq to drop these two sequences.
5. Create synonym s55 for student table. And query all rows from synonym. Then drop it.
6. Create view stv1 from student table by selecting roll, name , mark & branch column.
7. Waq to update marks from all rows from stv1 view.
8. Waq to create view stv2 from student table selecting roll, name, dob & mark of rollno 3 which can’t be
deleted from view.
9. Drop these two view from database.
10. Waq to create view st_fa from student & faculty selecting stu_roll, stu name, faculty id, faculty name
where rollno of student table should same to student roll of faculty table.
11. Select and drop st_fa view.
12. Waq to display the student roll, name, dob, mark and faculty name, subject, classroom, from student,
faculty table those student rollno are common to student rollno of faculty table using equi join.
13. Waq to display the all distinct rollno of student table those student rollnos are less than from faculty
table rollno using non equi join.
14. Waq to join student & faculty table without using any join command. And check how many rows
created.
15. Waq to check from faculty table, which student’s rollno and faculty’s id are same. Then display their
faculty names only.
16. Waq to display student roll,name & facult id, fac name from student and faculty tables those are
common roll no by using natural join.
17. Waq to display student’s roll,name and faculty id, fac name from student,faculty table by using ‘using’
clause.
18. Waq to display student roll,name & faculty id, fac name from student, faculty where faculty id and
student roll are same.
19. Waq to display student roll, name, mark, fac id, fac name from student, faculty table those are
common rollno to both table except those rollno of student table are also not matched to faculty
table.
20. Waq to display student roll, name, mark, faculty id, fac name from student,faculty table those are
common rollno except display fac id, fac name of corresponding rows of stu rollno of faculty table
those are not matched to student table rollno.
LIKE OUR FACEBOOK PAGE “JAVATECH 123” TO GET UPDATED NOTE & VIDEOS
Prepared By JAVATECH Search us in The World
**************************BEST OF LUCK***********************
Next – PLSQL will Start
PL-PROGRAMMING LANGUAGE+SQL
PROGRAMMING LANGUAGED USED WITH SQL STATEMENTIS CALLED PLSQL

More Related Content

What's hot (20)

Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
 
joins and subqueries in big data analysis
joins and subqueries in big data analysisjoins and subqueries in big data analysis
joins and subqueries in big data analysis
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
C functions
C functionsC functions
C functions
 
DML Commands
DML CommandsDML Commands
DML Commands
 
Group By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQLGroup By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQL
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
 
Data Manipulation Language
Data Manipulation LanguageData Manipulation Language
Data Manipulation Language
 
Sql queries questions and answers
Sql queries questions and answersSql queries questions and answers
Sql queries questions and answers
 
Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause
 
SQL UNION
SQL UNIONSQL UNION
SQL UNION
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
Sql joins
Sql joinsSql joins
Sql joins
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
set operators.pptx
set operators.pptxset operators.pptx
set operators.pptx
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
 
Sql operators & functions 3
Sql operators & functions 3Sql operators & functions 3
Sql operators & functions 3
 

Similar to Database object, sub query, Join Commands & Lab Assignment

Similar to Database object, sub query, Join Commands & Lab Assignment (20)

ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
Oracle
OracleOracle
Oracle
 
Dbms question
Dbms questionDbms question
Dbms question
 
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIts about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
 
Sql Queries
Sql QueriesSql Queries
Sql Queries
 
Chapter8 my sql revision tour
Chapter8 my sql revision tourChapter8 my sql revision tour
Chapter8 my sql revision tour
 
Spufi
SpufiSpufi
Spufi
 
30 08 Final Sql
30 08 Final Sql30 08 Final Sql
30 08 Final Sql
 
PLSQL Note
PLSQL NotePLSQL Note
PLSQL Note
 
Commands
CommandsCommands
Commands
 
Chapter9 more on database and sql
Chapter9 more on database and sqlChapter9 more on database and sql
Chapter9 more on database and sql
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
0808.pdf
0808.pdf0808.pdf
0808.pdf
 
Module03
Module03Module03
Module03
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
Microsoft SQL 000000000000000000001.pptx
Microsoft SQL 000000000000000000001.pptxMicrosoft SQL 000000000000000000001.pptx
Microsoft SQL 000000000000000000001.pptx
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
 
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek SharmaIntroduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 

Recently uploaded

A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationHelp Desk Migration
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?XfilesPro
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessWSO2
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAlluxio, Inc.
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1KnowledgeSeed
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfVictor Lopez
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockSkilrock Technologies
 
Benefits of Employee Monitoring Software
Benefits of  Employee Monitoring SoftwareBenefits of  Employee Monitoring Software
Benefits of Employee Monitoring SoftwareMera Monitor
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Gáspár Nagy
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfOrtus Solutions, Corp
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Krakówbim.edu.pl
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)Max Lee
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesNeo4j
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownloadvrstrong314
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAlluxio, Inc.
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisNeo4j
 

Recently uploaded (20)

Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by Skilrock
 
Benefits of Employee Monitoring Software
Benefits of  Employee Monitoring SoftwareBenefits of  Employee Monitoring Software
Benefits of Employee Monitoring Software
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 

Database object, sub query, Join Commands & Lab Assignment

  • 1. PreparedBy JAVATECH Search us in The World Chapter DiscussionAbout Database Object, SubQuery, Joining ( 3 chapters inone class) Database has few objects. They are 1. Table : Basic unit of storage which represented as rows and columns format. 2. View : It is logical subsets of data from more than one table. 3. Sequence : It is used to generate Unique integer number. 4. Synonym : It is an ulternate name for other database objects. 5. Index : Oracle server used index to faster access the rows using pointer. View : It is logical subsets of data from more than one table. There are two types of view. 1. Simple view 2. Complex View Why we use view 1. To restrict Data access : View doesnot allows to access all columns from table. It is created selected columns only. Importants columns hides from other user. 2. Make complex query easy : You don’t need everytime specify join command. Only write once complex commnd and make view. Then only access that view. Simple View The view which consists of only one tble is called simple view. The DML operation can perform with this view. If you want restrict DML operation you can write WITH READ ONLY statement to avoid DML operation Complex View The view which consists of more than one table is called Complex View. It restricts DML operation. ROLL NAME DOB MARK 1 A 12-JAN-1990 500 2 B 16-JUN-1992 408 3 C 19-JUL-2000 557 4 D 30-MAY-1997 300 5 E 22-SEP-2000 490 Create View v1 as select roll,mark from student; Above command create view name v1 consists of two column; You can define your own column inside view Create or replace view v1(MyRoll,MyMark) as select roll,mark from student;
  • 2. Above command updated your view (because i write replace command) with MyRoll and MyMark column. If you write select statement Select * from v1; It display like MyRoll MyMark 1 500 2 408 3 557 4 300 5 490 You can update view Update set mark=900 where roll=1; After select from v1 MyRoll MyMark 1 900 2 408 3 557 4 300 5 490 Same also updated in Table Select * from student; ROLL NAME DOB MARK 1 A 12-JAN-1990 900 2 B 16-JUN-1992 408 3 C 19-JUL-2000 557 4 D 30-MAY-1997 300 5 E 22-SEP-2000 490 If you want to restrict DML operation in view then use WITH READ ONLY E.g. Create View v2 as select roll,mark from student where roll=2 WITH READ ONLY; Then when you try to update view v2 whose roll is two it display arror.
  • 3. Complex view The view which consists of more than one table is called Complex table. Here DML command is restriction See the E.g Create view v3(MyRoll,MyName,MyDept,Price) as Select stud1.roll,stud1.name,dept.name,dept.price from stud,dept where stud.roll=dept.roll; Here you can see view v3 is (MyRoll,MyName,MyDept,Price) is created. It is consists of 4 columns. Sequence Sequence is used to create to generate unique integer values. Declaraton of Synnym Create sequence sequence_name : sequence name Increment by n - sequence increment by n, specify the interval between sequence number Strart with n – n is specified by the starting value of sequence Max value n – n specified where sequence number will be start. Min value n - n specify the minimum sequence no Cycle / nocycle – after reach at max valueit will be recycled. Means again starts value from minimum no. Cache n/ nocace – how many number oracle can allocate memory to store in memory. Numbers are faster access from memory. See how created ? Create sequence s1 //sequence name is s1 Increment by 1 //sequence is incremented by 1 Start with 3 //sequence start value MaxValue 30 //sequence will stop as it reached 30 MinValue 2 //After reached 30 next time it start from 2. Not again from start value. And minvalue //should less than start value. Cycle //cycle means value will be recycled after reach max value. Error:ORA-04013 Number to Cache must be less than one cycle. So max value should specify 22 or above. Default cache is 21. Sequence Created. To check sequence Select s1.nextval from dual; Select s1.currvalue from dual; To verify user sequence from user_sequence data dictionary SELECT sequence_name, min_value, max_value, increment_by, last_number FROM user_sequences;
  • 4. You can also write Insert into stud values(s1.nextval,’aa’,789); To drop sequence Drop sequence sequence_name; Drop sequence s1; Synonym It is called alternate name for table. E.g. Create synonym sn for student_sce_dept; Then instead of write big table name we use it through small name sn. E.g. select * from sn; it display data from student_sce_dept. To drop synonym Drop synonym sn; Index Is used by the Oracle server to speed up the retrieval of rows by using a pointer two types index Automatically: when we declare primary key or unique key. Manually: Users can create nonunique indexes on columns to speed up access to the rows. CREATE INDEX emp_last_name_idx ON employees(last_name); Index created. SUB QUERY It is called inner query. The query which is exists in another query is called inner query. It is also called nested query. Features 1. It is enclosed with parenthesis 2. It is written right side of outer query. 3. Inner query first executed then outer query executed.
  • 5. 4. Outer Query executed after result return from inner query. Two types of inner query Sometimes inner query returns two types result. First single result second multiple row result. Based upon this It is two types. 1. Single row return inner query 2. Multi row return inner query E.g. Select name from student where mark<(select mark from student where name=’Ramesh’); Right side is called inner query. First we should know what is mark of Ramesh. Then we select mark those are below ramesh mark. In bold and underlined mark is called inner query. Single row returns inner query operator 1. = 2. > 3. < 4. >= 5. <= 6. <> Multiple rows returns inner queries 1. IN : If outer query matched any value from IN operator then it returns result. 2. ANY : <ANY means Less than the maximum. >ANY means more than the minimum.=ANY is equivalent to IN 3. ALL : <ALL means less than the minimum and >ALL means more than the maximum. Select name from student where mark in (300,700,800); Or Select name from student where mark in(select mark from student where mark<900); JOIN command Join command is used to return query more than one table. Prior to Join Oracle8i or Prior 1. Cartesian Join 2. Equi-Join same as simple join same as inner join 3. Non-Equi Join 4. Outer Join 5. Self Join
  • 6. Oracle 9i or Next 1. Cross Join 2. Natural Join 3. Using clause 4. ON clause 5. Full or two sided outer join CartesianJoin When we specify join command invalid or ommit then result of cartesian join will be produced between two table. E.g. Selet roll,name,mark,branch from stud,dept; Here stud has 5 rows and dept has 4 rows. Then total 5*4=20 rows will be ceated. Equi Join: It is based upon equality of two values of same column of two different tables. It use the (=) operator. Select stud.roll,name,mark,branch from stud,dept where stud.roll=dept.roll; It display roll,name from stud table mark branch from dept table those roll are same to both table. (=) Table alias Select s.roll,s.name ,d.mark,d.branch from stud s,dept d where s.roll=d.roll; Above we specify alias name for both table s & d. S is alternate name for stud table and D is alternate name for Dept table. Advantages No need to write tablename repeatedly. Only use the shortcut name. For faster write the query. Ambiguity inColumn. Here roll is common column for stud and dept table. When we write query select roll,name,mark,branch from stud,dept ............. Oracle server will be confuse to take about roll. Because it is common. So we specify which table roll column we want to display. Modified query is Select stud.roll , name, mark branch from stud,dept where stud.roll=dept.roll;
  • 7. Non Equi Join The operator which are used other than (=) is called Non Equi Join. Operators are used 1. > 2. < 3. <> 4. Between Select s.name,d.mark from stud s,dept d where s.mark between d.high_mark and g.low_mark; Left outer Join / Right Outer Join / Full Outer Join Outer Join-It is an extension of inner join. It returns rows that are matched to both tables. And also returns those are not matched to another table. It returns the rows those are missed in join condition. Outer join symbol is (+) sign e.roll(+)=d.roll //left outer join It returns the rows that are matched to both table except return rows those that are not matched to the first table. e.roll=d.roll(+) //right outer join it returns the rows that are matched to both table except returns the rows that are not matched to the second table. Full outer join: The join between two tables, that returns the result of an inner join as well as the result of left outer join and return result of right join is a full outer join. Full outer join select name,mark from join7,join8 where join7.roll(+)=join8.roll union all select name,mark from join7,join8 where join7.roll=join8.roll(+) Right Outer Join select name,mark from join7,join8 where join7.roll=join8.roll(+); Left Outer Join select name,mark from join7,join8 where join7.roll(+)=join8.roll;
  • 8. Self Join From Stud d Natural Join Dept d; automatically choose same column name by oracle. From stud s join dept d using (roll) // using clause is used to specify column name by user choice in join condition From stud s join dept d on(s.roll=d.my_roll) on clause is used to specify that have different column name. Here roll & my_roll is not matched Left outer join select s.name,d.mark from join7 s left outer join join8 d on (s.roll=d.roll) Right outer join select s.name,d.mark from join7 s right outer join join8 d on (s.roll=d.roll) Full outer join select s.name,d.mark from join7 s full outer join join8 d on (s.roll=d.roll) Prepared By JAVATECH Search us in The World
  • 9. ASSIGNMENT ON DATABASE OBJECT,SUB-QUERY AND JOIN COMMAND STUDENT STU_ROLL NAME DOB MARK BRANCH SECTION AMIT 13/05/2010 600 SCE IT-1 AJAY 25/09/2009 550 IT IT-2 ROHIT 15/12/2008 450 IT CS-1 MUKESH 02/11/2007 390 SCE CS-2 JOHN 30/03/2005 400 IT CS-3 FACULTY FACULTY_ID FAC_NAME STU_ROLL FAC_SUBJECT CLASS_ROOM CLASS_DATE_TIME JOSEPH JAVA C1 STEPHEN C++ C2 RICHARDSON DOTNET C3 JAMES PHP C4 AKS ORACLE C5 TIPS:- CLASS_DATE_TIME DATATYPE IS TIMESTAMP(2) - TIMESTAMP IS USED FOR TO SPECIFY TIME. 2 MEANS AFTER SECOND VALUE FRACTION VALUE WON’T DISPLAY. ONLY TWO DIGIT SECOND DISPLAY. INSERT INTO TABLE VALUES(TO_DATE(’12-JAN-2001 13:34:56’,’DD-MON-YY HH24:MI:SS’)); 1. Enter exact data into student table. But roll should insert using sequence, it should start from 1 and increment by 1.[total 5 records] 2. Enter exact data into faculty table. But faculty id should insert using sequence, it should start from 1 and increment by 3[total 5 records]. E.g. 1, 4, 7, 10, 13 Also enter exact student roll into faculty table from referencing student table by using sequence but it should be increment by 2. E.g. 1, 3, 5, 7, 9 [total 5 records] 3. Waq to display sequence name, minimum value, maximum value from all created sequences. 4. Waq to drop these two sequences. 5. Create synonym s55 for student table. And query all rows from synonym. Then drop it. 6. Create view stv1 from student table by selecting roll, name , mark & branch column. 7. Waq to update marks from all rows from stv1 view. 8. Waq to create view stv2 from student table selecting roll, name, dob & mark of rollno 3 which can’t be deleted from view. 9. Drop these two view from database. 10. Waq to create view st_fa from student & faculty selecting stu_roll, stu name, faculty id, faculty name where rollno of student table should same to student roll of faculty table. 11. Select and drop st_fa view. 12. Waq to display the student roll, name, dob, mark and faculty name, subject, classroom, from student, faculty table those student rollno are common to student rollno of faculty table using equi join.
  • 10. 13. Waq to display the all distinct rollno of student table those student rollnos are less than from faculty table rollno using non equi join. 14. Waq to join student & faculty table without using any join command. And check how many rows created. 15. Waq to check from faculty table, which student’s rollno and faculty’s id are same. Then display their faculty names only. 16. Waq to display student roll,name & facult id, fac name from student and faculty tables those are common roll no by using natural join. 17. Waq to display student’s roll,name and faculty id, fac name from student,faculty table by using ‘using’ clause. 18. Waq to display student roll,name & faculty id, fac name from student, faculty where faculty id and student roll are same. 19. Waq to display student roll, name, mark, fac id, fac name from student, faculty table those are common rollno to both table except those rollno of student table are also not matched to faculty table. 20. Waq to display student roll, name, mark, faculty id, fac name from student,faculty table those are common rollno except display fac id, fac name of corresponding rows of stu rollno of faculty table those are not matched to student table rollno. LIKE OUR FACEBOOK PAGE “JAVATECH 123” TO GET UPDATED NOTE & VIDEOS Prepared By JAVATECH Search us in The World **************************BEST OF LUCK*********************** Next – PLSQL will Start PL-PROGRAMMING LANGUAGE+SQL PROGRAMMING LANGUAGED USED WITH SQL STATEMENTIS CALLED PLSQL