0% found this document useful (0 votes)
14 views

SQL Notes1

oracle

Uploaded by

Upendra Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
14 views

SQL Notes1

oracle

Uploaded by

Upendra Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 67
ortacle Sal S Area iq. dows ood Enter yl > 7a otpical sive Me Chbit | cast *ObSect of Oracle ee rh is Lied to, uyove intosmation 5 MeO + (onicany Tepesent Subset of data From One ox more, table. 3) Sequence + Used to qenesate Pr mony Key nasue. Tndex + 4h is ured to impaove the pasfoemanre of OF aerated obs 4 Vales fos Crate otab 9 Nome of rere > tate nase ‘Seamed 8 Comer Seamer Create sabie * Stud C Pol wurmdes NUMbES CS) - Name ion Varrehorrs (2 ) 7 | Rorliumb ox | some] * SQL Tn taodue Hor S Seu - Stands tox * Buery \anquse” Nery *latond| databsse sottwooss intract wirn o lanquay? Known a sage : because WS 0 simple english live lonquaye which Guideline are psovided 4 Standard Oxqaniration CAnst> adopied oy au -dutabale yendnrs Osacie live 1 MYSQl, THilrOsok+ ere --- An seis Nery COMPeY tanqguoge © weduace jy. ea [)) Qename- rename tdbie nde, Sunray + ye 40 pONamMe + sename rable-name *O dewhame » eq, TRNAMF Kabye EMP +o G @ prier .- Suntat \ Alter table yable-nam? Ade dokatype ; T-Name eq, alte tdlole Emp add salary Number (10) ¢ S raole altered. NDivverence perween dvuncade % AvP TVruneate Tuncare command 3f Wed to swemMove only table veind, Nie cam insest @ecord i table, e eq _ twuncate table emp: b sabre iuncated. Dp + dop command i wed 40 serooye toon sable gg +d? Tetowds egneo tl e +abje srsuciuy alo desop, eq, Wg) table ump. ’ > rabie davp. Cdata manipulade Canquage > «Th deal with dato of obvsects. I “Gh Provide > cornea 4 Insen t & Update Qinserdiy > Dedere. Syntax : MSea} S910 one ea. pda? Emp cet Rede ename = nyidya" Ohere Rid 2 to) ; > “Pame> whese & codition > where td 210) 3 Fe fi Pixs? tk 4 Faom, tob\e-namme > ; 10 [Display pavticuks record Wi Seleck x fxr atu where TONRO*? 5 iD dieth . a) Name column sch Name From srud 3 5 pre transaction OF dotabaie i+ orate ann Rasom srablecname> where condHen ry Operahon. 2 berween eed Owacte Qa OPetatos 19 SO * What 15 operators in SQL g an > OP enators ave Some chadatter ov Key which 15 we on an expression 10 om omy Opes asrion The operator of MO s aypes, ” ary SQL can be Cahkeqoazeof OPE AS ory eee oe : oy Ofer odov— Ary Pe) | opercatere f Lupton 7S "Dionay Minus m Mierset. ~ alter table srun daop Columy + xaddr¢ 55 + ‘erord in aeending order C ‘splay record. *S@C functton » tiWhad if function f ( Plainahion FuNckion are the opiect im sat which take PACT Mone inpul From user, 4aKe operation 2m inpw Gnd produce one ov move owput E 4- inpws =~ one ous put I ¢ More-dnpw —-__» More owput i E Pipes 5 Funct Os : Weqare Function | Group Function | mutti-row oo S916 ro. Function \ Function by Clause Perform tis Btn burees Not io database. BOW Function accept ™O one value. eS @ach yond and BUUTN OMe result fexaen BOS Function can be Nested up to PPh Yy DithH see ca, Whee amd Bee Y clause Ties of s;, 1 Choracten Purction “Numb ex Function Dote function ‘Seamed By Comer Seamer ‘Seamed Came Seame! e Fun CHO hs ap med) ¢ a-125 From dual, Onrss _ AbSuute tuncti oz, “ABs Function seu in the absolube Value DF py Be Given co RAP TENT on, Seen dbs ¢ Ly eats ®cery The ~ 18%) brsoen duu; cay BCD eur, ine nent ioseqey Yeah ig 4; 494 e than oF equal to g Sumber SMatert whole DUMHE greet ev om Ual to 4 Speci ties Number me | tpad CSubStr ( fe \R! EP) E salacy 42.000; tyacrioo eu Sdlory > ve (Salary, 0D7 gees Emprlarne salary Cormmidsson Alay Kurnor 30,000 cH Empid, empnam?, saary | comm sss’on, 4+ coremission totelsaleny Pree eps Emprdame, starry , AVL L Commission, oF $3100 AVL SdotYy,0 ) + AVL ( comms 3539p, 95 is a 1 Sa oe y Crom employee: Ale nul ond ANdtAUU Values Not Quy MaVING claude & ful explainan'on. clause sesincting tyne group MG Crouse will ways we use with Ree teciouse and evaucted aft ew forming °F groups, TM elimincses ine Non. Marching group. “UP oy ; Bee 1S used 45 OssANGE Sirmilax data erm 1940 Set of \ogical group AMIAX ¢ | -. Eero Serect col-mamet, colname 2 ,--- FTO name — AXOlo\e-name y qsoup toy column : 10 my Adbie Want to See How many depr 1° MY i ‘Sean By Comer Sener c+ dname, Countcx> Esorn Emp having Count Cr) 94 eoup oy Aname —dname, esal from emp having esal7 2000 ’Y dname, esol; “Wha 18 alias P Fuld Crplajraiion > SQL atias 8 column F tabie 1S uted to give o dempovary Name oi TE CaN use alias im 40 4ed0 woys % column alias 2) tab\0 alias, “Syntax + Column alias Select BO name. as Oomain WOhegrisy CON Staajn t Udetauy Not vay Che oi p>) Entity iNtegwry constaint 4 Unique Re by Pumary Key 2) Relerentsay Wntequity cortraint: Play KAY Constraings MPOSe integrity constrains Inside the time of table (Seaton oa + constrain + # we impose a default consivaint along With a CUMH hen tha column rested Bed Vimopliciys aw" value ond Pehaly of nu value it dubstitwe delaut Value, ETS Comsteaint oni y oRPlY on single Columns oa 3. Create sable emptbs ( eid nurnder (10), ename BPO) ah Kuen ex ¢ 10) cleFoutt 100005: inoery WFO eMPAb) ( eich, Ename> Value (0), ‘anyit): ey dekaut | not inserted wto insert CHECK constsaj n+ allow The chece Fed Value in a column - lumo : ingle co ODStrains Bageorny 1m 8M P2¥ cam be tmposes babe level and Column level BOBS Stu Coino Oumber Check CrO11N0 Bo) name Vorchar (no) ) + Indext into atu volue Cz0,, > Abhi’); SIT —> Checy COM Stain 4 CS: GUL Violen Ino StU Vale, ee Pb hi). innegn'ty Constveun f # ofoa) Uy r entity inteqaity constrasn inser} “nique value ona Column TWo WWpey Be oDiGUe tonsirciiny 2. Primary Key constraint Oniaque Uique ONStBain} gejbwe} + Pamory Fey constrains 40 inser s dupiicare Nalue TAI CH to inserg Be Column, rue mee Value on o eolumn gy weu oy n . MDD uy Vellue, PULL oy alias ne “aire Can pe dering 1 one. OMe e Unique I or MUU pro Const ot BRDPOA,., rey) id number Psion y Key, €sal Nurovdey 9; t into SOP Cio! , ‘Vitay’ 19000); 4 140 exnp II Vi rpayfa’, 10000)" It oreay Pereat called crn\d AHoIe e Foveiqn Fey ye values mut oluronr this Column to Teherence Key ¢ child tebe, eae eonps cet Vor! Yanriy’ )F000 MOdsg, : _ “ankush’ 1000, \46 ym | Seen rs 12 ~| hho 14o she Employee Which Deptrame 1S. ccie Sees? Emp ehere Deptip ing Did Crom deps eee a6! 5; \ whien Salary Tayo. Seer where Did ToC ale ah ‘Sean By Comer Seamer YY Clouse. a] j e Rin SQL. Wha i§ omer bY clause 9 We use osdes bY clause to AvTeMGe the wecowg BUEOReLos Move Cec orcling onder columns eisher ascending or rte + 4 Sovts the -secord OY defaurts. Suntan : in ascending onder Select x fom 24able-namy orden 8 COluron ans Sc] dese, * Tabo\e EmpPemeo Ename Income Doy anti} 20000 ae eee uray 0000 eee: 5, \Sovo ‘Ss BORA 0-05 6 Pt 0- ne, — 20000 04 -Fan- lars Ne Form test wnere by fame dese : 2 @ the business ule’ which culoaet +O. BE siaic popes data inside sabie, 3 osoce tne Inteqtity consivaints ciassitied \nto S-QsOUPs . *Classificaton of ConstsaiNts % Borman integrity const saint. > detawt Noy null check. D EMlity intequity consisaint a | i> Unique ¥ey b> Primoty Key. % Ret éenrial inrequty constraint >) impose loreqsty constraint fosido the time of fable CBO On gaity constaaind § ’ ait Per icalni quod wi to Insert a “column ; : a © are 40 +4PeS OF ae ey ree Constaun Apaimany Constaaint % unique constraint : — ; | ue Key Prmory Key MAE “Constraint werrcl | 4: Pairary Key consteaind 'IMSext cluplicate value Ferigct to insert NA Column but it attow duplicate yalue ong Vode. column as wetlr ay Bec: Na value. be detine ig one ‘ 2 onlixe Unique Constraint muttipie ' B ooo table contain onty | one eer Fey column, | | ‘Key 15 Setot one or more S]eotumns of a Aable tad Uniquely Wentisy a mecord in a datdbase table. + Saki of "YOU can say snot it is little live Primary rey ! but it can acceps only one Nu value and 1+ cannot Rove duplicare yatier + DeFni 4 a uoique Fey constraint 0 Single F COlumn, Create sdole Student ( S-Id number unique , | Lastdame Vvarcharn (10> , Fixitname Narscharn C30), C144 varchar (30) ): Bekining a unique key constraint of rowtiple : UMNS IE AMIE Student C Std number ¢109,las!-Name | cn20) » Plastename Nosscharn ¢s0D Aoi Sows eres ny) -TA, Lasiname 5 as y epapin t. taint of Altes Tobie, th 3% OUALY IS x = Adld Unig cic = Saini Be agms> ‘Sb “primary Key, You iO} when teu cnet {briny Fe, Povees ne copay inteqayy % Basa ba unique, daa. atin cannot ve exee exceedea] , *4 01 Alles Janie, 2 MeO ave 1§ already created and qou wank to Rake og Paimnarcy Key condtraint of S80" colurnn you should we Fo\\owing : Parmar y ¥RY ON one columo Mtee jamie student add Paimary Fey (S15 TPwmory Key on multiple columns. Biter satcre student add corstsal N+ Prsiudtd Primary Key (sto, Laut Name > *How to deop Pricoary Key conotoaing BES ident > deop constraint PK _studTO Copying Rows FrOTM Another table ¥ Sylar MSex} into KFixst-table-namne> (cols, Co1a,---> | 4 p Select col, 0a, Cola --- From set a pw value > where condingn - There one F tyPa Join iO Sq Ter disicr, Be OU have minimum Two tabie. “act least one ae SIUM AOTE AMEN. Ip I bor, table. => To Show the MUHPIE secorol From MU Hipie taloje 'Dt0 One tabie, | oO equi To}n *“Saecs * Peso emp | emMPdem og Where E™MPdemo vig 3 a sid = Prole SSiong] \sowr teather chottor teathex codev Cashion ts0omM Beare! cddeees = woo 00 ore sond: sd > Pessonal, Professiond| Where Pex Persona). ids fesorn Host <88600d-tab1e-na pn (6 ae “hab faeces - eps bal ya 4 ee ck Name, Contact, dept $3 0m Persona Bnet Soin Peofession al on Persona). td — OFessiongs vid: mel, colo, Cols proct 4 First - babie-nampy. “Pame> on Athod? pepe meg PS AMeoites column Pome > » & Similar Colurmna £8 etond -tdbie— Name. be as. OPE bat ip Ww, Fevemy to omte. OWT Join © Ft outer soin @ wight outer Join Olett ower Join “AM -secosd of Fixst table and only match Record OF second +tabie. Select name, odd, dept gaom Persona lett owpey ' Join Prohessiona) on CPeronal: id = profewional-jf ds — synrar. Eee a ; Col, , Colm, Cola, Coly Fsom on Cee fable-name. cermmon column Name =) selene | * COMMON column Name 5 5 aw the secosds dh left tab. ght table quo. + dame address, dept From Perea Fu outer Join Perotessiong) on (¢ Pesson a: id = Prohessinal: id) Col,, Colo ,COly Pom on C Fiesp — Fale namo, common WColumnname = Seco nal AbIe-name. COMMON column Dame a oppiy op ony *AbIe. = 700 columo secord wI\) D0? Match ase $0010 BN one s+abie same at !¢ Select P4. name, Pi,addtess , PA+c Fs0m pessond,P! , Persone po ‘Seamed 8 Came Seame! Expression HME Case expression goer Hrsoug h conc and Felurn a value when the inst . Condi tor 15 meet (|e -i¢ - then —else sictensot Er00 Conditons ave asue, 14 weuin He Value in the ELSE clause. Bete 7. no else Part and no condiHon MO conditon are true, it veburns Wall: Syniax * Gene Case . Bbc o, When When Condiion Thes weSut 4 Condition shen weSsUIE ND Condition then Tesulls Else other veut s ~ Nery 4000)’ ac e's

You might also like