SQL Introduction
SQL Introduction
SQL Trntaoduction
ypes DBMS -
of
@pmagramnen-gul
RelationalDBNS
Non- Relational DBNS.
table FOmat.
RollNO Name cla&s
Jai 5th
2 Aman th
3
Anuj 5th
Ram 8+h
CRelational DBNS)
|Fon Examþle- NysqL,Oacle.
Page 2 of 34
RollNo": 1,
class":"sth",
name: Ta"
CNon-RelationalDBNS)
SQL s used o
ubdate, delete, insent data in
table oh Relational DataBaáe.
SQL
RDBMS
Relationoal
DataBase
@psogammeh qinl.
Page 3 of 34
Date :
|Tage Na :
Syatax
CREATE TABLE tobleName(
Column1 datatype,
Column 2 dataube,
Fos Examhle
CRERTE TABLE UBes
FiAstName vohchaây
TNLastNameuahcho,'i
EmoilidNascho;
passiosd Naschah
EisstNomellastNamelEmail idLpoAswOhd
-@pogammen-gin.
Page 4 of 34
SQL TNSERT
INTO Cormmand
It i8 Used to data
inset into tables.
Syatax
INSERT INTO_ tableName Ccolumn
column2
VALWES(value14Value2..
A O o
database table. is knouon as
hecoad
OA a tuhle.
A
column oß database table i8 knoah06 an
attaibute.
@paograminehgini
Eoh Exomple
Examble @pogsammes-qinl
IEinstName LastNannePassNohd
Tai kumas I22i
Singh abc
Arnit shasma
Table '- USER
Command -
SELEC EinatName
Fhom USER
Duthut
FinstName
Arott
Page 6 of 34
Tage Na :
SQLQuen
@pagrammea ginß..
:
Page 7 of 34
|J'age Wa
ERON- H
is Used to sloeciy the tables aom.
Which data etched.
WHERE_ ¥
to iltes secohds based
is Used on.
LGROUP BY E
is U8ed to grou hecobds based
sequinemernt.
s UBed to
|HANTNG H
tten ghoup
-
ORDER BY i6 uBed to Bot the data in.
ascending o descending ondes.
-@pAogamnmen.qjnl..
Page 8 of 34
SQL
Constsaints
Constsajhts
@phagammeaaginl
Calumn.
oa
EROM
AHFRE
HAVENG
SELEGE
-ORDER BYE
@pragammesgal..
Page 11 of 34
|Date :
|Tage Na :
Mly Ghambion
@pagtamneaginl
Page 12 of 34
Tage Na :
Mly Ghambion
Systas
SELECT DISTINCT
coumn.hame
FROM_ tablename ,
Examhle
FisstNameLastName Passhiosd
Tai Kumas 123
Singh d23
Amit Shaam0
Table i USER
Command PasgDAd
SELECT Distinct
FRON USER
Outhut
Posshtosd
12.3
-@pagpammea-ginl
Page 13 of 34
Jage Na :
M hambior
H
s used to iltes row8 in a table based
&hecified Condition.
Syatax
SELECTcolumn-hame
FRON table-name
iHERE conditich,
Example'
FisstNome LastName
Jai Kumas
Singh 20
21
Amit Shaama
Table'- USER
-
Command
SELECT EinstName, Laat Name
FROM USER
WHERE
Amit Shabma
@psagammes-gil
Page 14 of 34
|Date :
Tage Na :
-M Ghampion
SQL
AND -
The AND_oþeratoh
Aetunnstaue i both.
Condition ahe
taueand false otheawise.
Syntax WHERE
Condition1 AND_Condition25
SQL
OR
t hetuhns thue ip eitheh Conditon
is.
tnue,and false i bth conditions ase
false..
@phagrammeh-ginl
5QL ORDER BY
SELECT Columnl,column2.,
FRON tablename
ORDER By Calumn4 CASCJLDESC]ycolumn2
CAscIfDESCJ,
Exagple
Fi2stNanne Lastame
Jai Kumas 44
Sihgh 20
Amit Shabmo 2.1
Table Uaea
Command'
SELECT k
ERON VBes
ORDER BY
Outhut
FiastName lAstName
Singh 20
Amit Shaàma 21
Kumas
Page 16 of 34
INSERT TNTO -
Sytaxe
Thseat into tablename(column1,column2,)
Values C valued,value 2,;
Examble
Eia&tNome lastame
Jai Kumas
Singh
Aait Shasma 20
Table'- Uses
Command
Tnseat into uses CÉiRstName,lastName, lgc)
Nalues ( abe, y2, 25)3
@psagamma-gil.
outhut
EnstName LastNome Age
Jai Kuman
Singh 15
Amit shaahma 20
abe 25
Page 17 of 34
:
|Page Na
SELECT e
Calumni,Column2
Fh.om tablename
HERE column2 TS NULL
TS NDT NULL
SELECT Column4column 2
FRON tablename
iWHERE Calumh1 TS NOT NÚLL;
@paogammesgil
Page 18 of 34
Page Na
SQL UPDATE -
Tt is
used to modiy existing
data in table.
Syntax:
UPDATE table-hame
SET Column1= ValuelColümn2=Value2,
WHERE
8ome-Column: Some-Nalue 3
Examlale
FiastNanmeLastName Age
Kumas
Stngh 15
Amit Shasma 20
Table'- USeAg
LCommand
DPDATE USERS
outhut EtastNameLastName
Tai kumah
Singh. l6
Amit Shasmg 21
Page 19 of 34
|Tage Na :
My Ghanbion
SQL DELETE
H
is used to_emove existingkecohd fham
a a
tablein SQL Database..
@psogiamardsgi.
Page 20 of 34
|Date :
|Page Ne:
-My Ghampion
5QL
Wildcasds i
wildcands ase
SQL
8hecial chaactess used
in
LIKE' chenato, to Beanch
patteah in a column foaa speciyc
ofa table.
The percent sign (l) heþresents zeso, Ohe
Ot multEiple
chahactes..
The undehscohe sign (-)_aelþaesents one,
Single chahactet.
SQL LIKE
It is used to
q
&eahch fon a
a
sþeciic
pattesn in column of table
Syptax -
SELECT Column1,Column2,
FRON tablename
WHERE colunn-nameLIKE pattesn;
@paagames-gial
Page 21 of 34
SQL TN -
t is
WHERE
used to sþeciy multiple walues
ina
Clause for Rilteaing
data.
SELECT
columnicolunmn2,
FROM table-hame
WHERE Columnname IN CValue1,Value2);
6QL Betneen i
Syntax
SELECT
Columhi, column2;
ERON table-hame
WHERE Column-hame Between
Value1_AND Value 2
Syuta
SELECT column-hame AS
alaß hame
Ehom table.aname
Page 22 of 34
A
Syntaxje
SELECT Columnn.hame
FRON table-hame-1.
UNION
SELECT column-hame
ERON table-name-23
@paogsammen-ginl
Page 23 of 34
SQL GROUP BY
H is u8ed to grouhhOJA that
haue the Bamevalues into Summahy
hoWs,Like Find the numben of customehsin
each ciby
SQL HAVING Lt to
is used
the aesult& o ilte
GRoUP BY' queny Based _on the
0.
a
SQL ALL Used
Fishesult to Combane ualue usith
the of
subquesy a
H
retusns taue ip the value is thue oh all elenmenta
@pAogsammea-gial-
Page 24 of 34
:
Tage Na
a
Taonsaction EOAL i- These occCus ushen
taansaction qails due to pablena ith Iaoking
@pagamme-gial.
Page 25 of 34
SQL JOTNS
INNER JoIN
LEET JoTN
RTGHT JoTN
FuLL ToIN
@agzamnegial
Page 26 of 34
INNER JOIN
SELECT
columnhame
ERON table1
INNER ToIN table 2.
LEET TOIN
LEFT TOTN
ept
-Aetusnsiall Aecords faom th
table and matched econds from the
ight
AZ 2
table
tables t
SELECT
column-hame
ERDN table4
2.
LeET ToIN table
ON
table4. colunmn-name= table2.Column-name
Soibe
Page 28 of 34
KIGHT JOIN
RTGHT
ToIN- TH
hetuxns all secohds thom.
the aight table and the matched hecohds
hom the ept.
table1< table 2
ON
tablei.column-hame =table 2.column-narme;
Soiþe...
Page 29 of 34
FULL
5/5
TOIN
EDLL ToTN - TH
2etuans all Aecondá when
a
thehe is match in eitheh the left table
ight table.
<
tablei 4able 2
SELECT Column-name
4
IERON table
Full ouTER TOTN table 2..
LON table1.column-hame =table 2.Column-hame
HERE condition..
@paganmegisl
Page 30 of 34
SVlax'
Cheate table tablenamel
clumnl dotatye
columnz datotye
Bumany kesltolumn name).
A
> tableCan cohtain only Ohe
Page 31 of 34
C
Cheate tabletablename
columni datatype
column 2 datatypes
- J.
konagh keylcolumn
name]
Re} ežnces lpumasykoydable
Page 32 of 34
TAKE ExAMPLE
LET'S
Student
RollNDName Addhess.
Prninas RAM DElhi
2 Lalit Mumbal
3 RAM Delhi
10'/o
90 o Golo 20/o.
10b So
Page 33 of 34
Nthslscince bnglish
20/o.
So21.
You want tocheckRolND 3nasks jn.
maths,FohLign key Ccme into pictuse.
Stuclent table kesut table.
Ne have to add phimag K
fo reign
2)%
Page 34 of 34