SQL (Structured Quary Language) : Nikhil Jha
SQL (Structured Quary Language) : Nikhil Jha
DATA BASE: - database is a place and medium where we are storing the data in
systematic and organised way....
NIKHIL JHA
SQL (Structured Quary Language)
1. COLUMNS: -
• vertical position of the table.
• known as attributes and field.
2. ROWS: -
• Horizontal position of the table.
• known as RECORD & TUPLES
3. CELL: -
• Smallest unit in the table called cell.
• intersection of rows and columns.
*********************************************************************
RULES OF E F CODD: four rules
• data inters to a cell must be a single value
• we can store the data in multiple table if needed we can establish the
connection between two tables with the help of key attributes.
• in RDBMS we store the data in the form of table .it includes meta data.
➢ META DATA: - details about the data which is given in table.
➢ it is auto generated
• data can be validated in two steps
1. By assigning data types
2. By assigning constraints.
DATA-TYPE: -
• what type of data to be store in a particular memory location
• five types.
1. CHAR
2. VARCHAR/ VARCHAR2
3. DATE
4. NUMBER
5. LARGE OBJECT.
#- CHARACTER LARGE OBJECT.
#- BINARY LARGE OBJECT.
NIKHIL JHA
SQL (Structured Quary Language)
1. CHAR: -
• it can accept 'A-Z', 'a-z’, '0-9', 'special character', alpha numeric.
• enclosed with single (' ').
• SYNTEX: - CHAR(SIZE).
• 2000 character.
• fixed length memory allocation.
2. VARCHAR: -
• updating of varchar.
• size 4000
• using coz of storage
3.DATE :
• there are two format given by the Oracle which is 'DD/MM/YYYY' AND
'DD/MM/YY'.
• SYNTEX:- DATE
4.NUMBER:-
• SYNTEX:- NUMBER( PRECISION, [SCALE])
• scale is optional.
• default value for scale is 0.
5.LARGE OBJECT :-
• CHARACTER LARGE OBJECT:- USE TO STORE CHAR TILL 4GB.
SYNTEX: - CLOB
• BINARY LARGE OBJECT:-it is used to store binary value of image, mp3,mp4,
doc etc up to 4gb.
SYNTEX :- BLOB.
NIKHIL JHA
SQL (Structured Quary Language)
CONSTRAINT:
it is rule given to the column for validation.
TYPES OF CONSTRAINTS:
1. UNIQUE
2. NOT NULL
3. CHECK
4. PRIMARY KEY
5. Foreign KEY
NIKHIL JHA
SQL (Structured Quary Language)
OVERVIEW OF SQL STATEMENT :-
1. Data definition language (ddl)
2. Data manipulation language (DML)
3. Transection control language (TCL)
4. Data control language (DCL)
5. Data quary language (DQL)
a. SELECT:- it will fetch the data from the table and display.
b. PROJECTION:- it will fetch the data from the table by selecting only the
table.
c. Selection:- it will fetch the data from the table by selecting the both
rows and columns.
d. JOINS:- it will fetch the data from the multiple table simultaneously
*********************************************************************
FUNCTION :-
• block of code or list used to perform some specific task
• two types.
FUNCTION
1. MAX ()
2. MIN ()
3. SUM ()
4. AVG ()
5. COUNT ()
NIKHIL JHA
SQL (Structured Quary Language)
• multi row fn can't accept null value
• use more than 1 multi row inside select clause.
*********************************************************************
GROUP BY CLAUSE: -
• used to group the record
• executes after execution of from clause
• executes row by row.
• any clause executes after the group by clause will executes group by group.
Syntax:-
o select group fn / group by expression
o From table name
o Where<filter condition>
o Group by col name / exp.
HAVING CLAUSE: used to filter the groups.
Syntax:-
o select group fn / group by expression
o From table name
o Where<filter condition>
o Group by col name / exp.
o Having <group- filter - condition>.
*********************************************************************
SUB QUARY :-
• a query written inside another query.
• inner query executes first and produce the op
• the op of inner query will be given as ip to the outer query
• And the outer query will executes and produce the result
• there for outer query is completely dependent on inner query.
• two types of sub query:-
1. Mingle row
2. Multi row
• two types of sub query operator
1. All
2. Any
NIKHIL JHA
SQL (Structured Quary Language)
*********************************************************************
JOINS:-
• it is the process of RETRIEVE or fetch the data from multiple table
simultaneously.
• FIVE types
1. Cross join/ Cartesian join
2. Inner join / equi join
3. Outer join.
a. left outer join
b. Right outer join
c. Full outer join
4. Natural join.
5. Self join
1. Cross join: the record from table one will merge with all the record from table 2.
SYNTEX: Select col name
From tn 1, tn 2 ;
2. Inner join:- it is used to obtain only matching record.
SYNTEX- SELECT COL NAME
FROM TN 1, TN 2
WHERE<JOIN CONDITION>;
3. OUTER JOIN:- it is used to obtain unmatched records.
o Left outer join:- it is used to obtain matched record from both the table
as well as unmatched records from left table.
o Right outer join:- it is used to obtain matched record from both table
as well as unmatched records from right table.
o Full outer join:- it is used to obtain unmatched records from the both
table as well as matched record
4. Natural join:-
• whenever there is relation between two table it will act like inner join.
• whenever there is no relation between two table it will act like cross join .
___________________________________________
NIKHIL JHA
SQL (Structured Quary Language)
CORRELATED SUBQUARY: -
• A query written inside another query and inner and outer query are
dependent on each other it's known as co related sub query.
• Types:
SET OPERATOR:
1.UNION: IT IS USED to combine the result of two statements and it will remove duplicate value.
2. UNION ALL: it is used to combine the result of two statements or it will not remove the duplicate
value.
3. INTERSECTION: it is used to combine the result of two statements and ot will give the common
records between two statements
4. MINUS: it is used to display the records present in table 1 and the same records which are not
present in the result
• Pseudo column or false column which are present in each and every table and must be
called explicitly.
• We have two types of pseudo column 1. ROW_ID 2.ROW_NUM
NIKHIL JHA
SQL (Structured Quary Language)
STATEMENTS:
1. DATA DEFNITION LANGUAGE (DDL)
2. DATA MANIPULATION LANGUAGE (DML)
3. DATA CONTROL LANGUAGE (DCL)
4. TRANSECTION CONTROL LANGUAGE (TCL)
5. DATA QUARY LANGUAGE (DQL)
NIKHIL JHA