0% found this document useful (0 votes)
15 views12 pages

Wa0003

Uploaded by

Saif Ali Khan
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)
15 views12 pages

Wa0003

Uploaded by

Saif Ali Khan
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/ 12

Topic. Date. Page No...

.........es..

M05
Name i Nisha Hbi
Class : MBA EM 2nd Seroeste)
Role No. : 125

Eaculky No. 23EMMCA 125

Submitted To i DH M. Shahid
Topic.... Date. Page No...

ston
(MEC2005)
Decobe the follousing commanla ay nantianing thike,
gntax and esample"
1 CREATE TABLE
WBe;The CREATE TABLE Atatement is od to cheote a nie
tableu a dotabaxe.
Syntax i CREATE TABLE tableName
Ccotuont datatybe,, calunal datakys,
EATE TAGLE Emplayes
CREA
EmployuID int NOT NUL
Name VOHchas0)NOT NUL
Depaxtment vanchax(30) NOT NOL,
ContatNo nt NOT NU
Email yaKchat(30)
PRIMARY KEY (EmplayeelD))

2" LNGERI INTO


Oae i Ihe INSERI TNTO' statement. i ed to inseut
nes Hecauda o4 olatan the table.
Syntaz
TNSER TNTO tablName
VALVES Cvalue,waez,)
Thu coromand. can be stol atileAntexing uadding valuea
a all the calumns of the table. Oxdax a thu vaues
Topic. Date.... Page No...

Ahould be same as the andes al colunan in thu tabls.


lo inaut values in the becilic colinan we can Ae
dh
the follousing statementi
INSERT INTo doble ncume (colusani,colum2,)
NALUES Cvalue,walz,)
Example:
INSERT INTO Eabiayees (EmplaeeID, Name Depstmant,
ContactNoEmail)
VALUES
('1O1, Rai','HR,'9a9o0012.34 hajioLgroail aco)
l02,3ia'Fincoe998o00a12AaLD2gmailecom
(103,Chxia,"HR 98910002.34,chiialo3@roailo co),
(o4TAhaiMakating' 968oo01234,' iahaougmailcom
3 SELECT
Use The 'sELECT' AtateMant iu ued to select dota tom a
da tasae
Byntazi SELECT counml,colwan,
PROMtablname

To seeLotun all colwmna ithout peciyimg calmn


Aytax
SELECT EROM Eahlayceas
Output.
Embloyte ID Name
Debaxtmnt Contact Na Email
HR 9890001234
102. Sia Einance q98 O00DI24 ajngmailuton
AialsAgoraiktorm
T03 Chaia HR 9891000234 ChxúalHgmailcom
Iaha Monksting. 6800O234
Topic.. Date. IPage No.......**

SELECT Name,DapaHtiaent FROM Enaplayeeay


Qutpui
NOme DepautMent
Rai HR
Sia Rinaunce
Chs HR
Laha
Maskahng
Y.SELECI DISTINCTI
WAei The SELET NISTINLT' tate ment in eedto etuUn
snly dint (ditinct) aauea
Syntuai
SELEC DISTINCI coliumn colann2,
EROM tablename
Examplui
SELECI DISTINCI Debautme nt ERoM Enaploe
Othut
Deboudment
Finance
HR

Maskating
5. wHERE
WAei The "uHEREd
to pilteN MeCOMdh and to extHact
anly thoe coMcda athot fulill a fecifid conditien.
SELECI colamni,calumn
EROM tahli nme
WHEREcondittoa4
Topi... Date.............*. Page No...

Eaamplei
SELECT EablaeID, Name ERoM Emplayts
WHERE Debaxtnent a ' HR
Outpudi
EmployeeID Nome.

03 Chuis

ORDER BY

asLendian udeacnding
3ELECI ealumat, calumm2,ee
FROMtablenon
ORDER AY colan Ly calumn2, Asc{DEScy

Examplei
SELECT EmployeiD EROM
oRDER BY Noume DESC

Qutput
EaployeLD
102

AND OR ANOT
WAeS) Th 'ANO' opexatsiwd ta filten ecasca bastd on

iall conditten a
|Topic. Date..... Page No.....n

ciis The 'oR' ohatas idlsd ta feltenHRCAMde baLd an


moe taon ane conditian ad it diaplaya ecoHd
any tae canditian a tHue

the. afpaste Meult,alo


calliditae nigatie eulte
SyntaxiSELECT CalhimnLcolumn2,
EROMtohle nane
WHERE conditien AND/oR condition2

SELECT column 1,conn


EROM tablenme
WHERE NOI Candition

Exafnplei
SELECI Name FROM Emblcyees
wHERE Depotmnt'HR' AND EmployeID T0
Output NamOe
CARIS

SELEC T Name EROM Emhloyees


wOHERE Employee ID >102 OR Depo tnentz HR'
Output Name
Chya
Lsha

Raj
SELECI Nome ,EmplayeID EROM Enplayeea
uoHERE NOT Depaxtment =HR
Topic. Date. Page No....

tput
EmþloyeID
102
Tsha

Ts NU & IS NOT NUU


Wse Th IS NOL' cheotoH Adeed to tent
The IS NOT NOL openatáx s wicod to tent at non
valueA,

SLECI colionfcalunan 2
EROMtabl nce
wHERE calimnname IS NULTS NoT NOLL
Examplei
SETECI Emplayee ID Nanae EROM Eoaployeea
OHERE Emol IS NUL
Output i
EmplayeID Nome

UPDAIE

ataale The wHERE claue coich hecod is to be ubloted.


Sgniaxi
UPOATE table nam
SET colunni=valuecoluumn2 EVau
HERE Conditan
|Examplai
DPDATE ErmployeA
SEI Depaxtment.= "Prouctíon'
DHERE EmplayeeID l3
Dabastnanent chai no) PHoructfan,
Topic.. Date..... Page No....

IODELE TE
DELE IE'à ed to cdeleteeiting Hecand inatabde
WHEREclaee shecilie ushich ecAHdi to oe dalted

tabletle bl deleted
agntani
DELETE FROM table Name HERE COndition
Example
DELE TE FROM Eahloyes WHERE Emplouee1D=lo
DROP Table
DROP TAALE data delete dae table tomhlitely
DROP TA BLE tablenCme
Exanmpli
OROR TABLE Cwtome

12SELECT TOP and LIMII


Ose The SSELECT TOP'ed to specilyte numbex af
HeCOHca to etn
LIMIT' cdauei ed to select a limited nunmbn e
Aecorda
Syntaxi
SELECT TOP numbe/penernt columaname SELECI cowmnname
EROMtablname. EROM tablinome
SHERE cOnditon wHERE conditign
LIMI numbe

Exampls SELECT Top 2 Name FROM Enylau SELECT Name fRoM tmblayes
wOHERE EmplbyeID Z104
LIMLT 2
Topic. Date.
Page No.. ........

Qutput i
NAMP
SIA
CHRIS

13. MIN () and MAX)


Usei The MN Ounckan utin the Amallut vale
the elected colimn
The 'MAX0'uneton knn the laHLit walu atthe
Alte colmn
Syntaai
SELECI MLN (CaLum name) MAX (calmnnan)
FROM dablhname
wHERE conditian
Examalei
SELECT MIN (EnployeID) AS Smalleat ID
EROM Lmployees
SmaltID
QAtputi

UAL The oUNI) uactien netwns the numbax MOAthat


(xite'en
coemn-name
SELECT CoLUNT()
Ryntaxi
FROM tablenome
wHEKE canditton j
Examplhi
SeELI CoUNT(*)
CM Emplays
FROM
Topic.. | Date.
Page No...

UseTheSUM() fnctonetusne the total


The 'AvGO fntianHhns the

Syntaxi
SELECT SUM(Connnam) 3EIECT AVG(coumn neme
EROM tablname
EROMtablenan
uOHERE concitien OHERE Conditien

xamplai
SEIECT sUM(Quant SELECT AVG(Pce)
FROM Ondendtala EROM Pacdcte
15. JoIN
UAe A JOIN cdouseiA Ad to CAmbine Hos omtuo
mone tabler bosecd on a tlated calnmn batuseen them

i) (IN NER ToIN 3Rotusun HOcOYolathat have


values n both tols
mtcking
tahle and tae matched ecOHdA Athe
igat table
D
table ond the nmotched tecaHds DO the.

aa) EOLL(OUTER ) JOLN : Retuuns all secoHcds wshen thueu a


matchin cithen att an iglt tasle.
Syataxi
SELECT ahleletolumastablcolunmi
EROM tablel
TNNER JOIN to lble 2 ON tabla1
Topic. Date.. Page No...

SELECT CHceaOrdexzO,cutomea CastomerName DHdaxs.ObdatyPate


EROM OHdos
INNIER JOLN Cutome ON OHn aa Custoen ID : lustonhy
CutomuID

UNION
UAe The 'NION' spaxatex sd to cêmhine the eult-st
tuo a maMe Aclect atetemande Evexy SELECT tatemd
usitlain UNTON mst have tai eme nuAmbln a colunaLsith
sinilaH datathhei. To clloo duplicate value, ise UNION ALL

SELEC colmn honels) EROM tables


(NTON

SELECT colmnnamel)EROM tahe

SELELT Cit FROM etomlte


UNION

SELELT Ctay EROM Suppliek


OROER BY city

HAVING
VAe he HAVING clause as addad to SQL becausL the HERE

keyacraud cannat hi ud aith Lgnte functan


SEL ECI Coumnnamla) EROM tabl nane WHERE COndtion
Gkoue By column naneCA) HAVING, Condtion.
OROER BY column nam(a)
Exampai
SELELT COUNIT (CLatomsI), Conty
FROM CustomeM

HAVING CoNTÍUtomay TO>S


Topic. Date. Page No....

ALTER TABLE
The ALTER TALE' tatement is ed to cdd,dalete a
nodliby clumna in nexistng table . Tti ud ta add
and drAp vakicLA CSnitHQinda an anesting taal
To To ctotate ucoturys
ALTER TAGLE tasla nane ALTER TABLE tablo name
ADD cnlnnome DROP COLLOMN colwmnname
datatyt
To sttntemt t t o t t e b t t
ALTER TABLE tablo name
RENAME COLUME ald nage to nen namne

Exampu i
ALTER TABLE Pesonb
ADD Dateo Biath dates
ALTER TAGLE Posona
DROP COLUNN
Dateoksixat

You might also like