SQL Notes

You might also like

Download as pdf
Download as pdf
You are on page 1of 41
try el Gsloucned Guess tenguage)- gramming languag. wage _( Genera] O1__purpoSse | ~ - ae like PY then Tava, , ae pose Ruby pH ~—50__an_ nie lan Uages __are@__known | a5 general__purpose languages “because we can tse Oil hice || anguages_+o__develop a particular _____ Software. For —9—_parHcular _ came — © saris not a_pregramming. a “la ng: wag. e. —@_n__general purpose language 12 ewe _ux ane = to__corite Q im ___ Coe _neec| te tel) — things one 15 “chat to do? 2.ts how 4 Domain Specie Language = __ dns = art 7 @©_sar is one oF the damain Spectkic ——_@_1n__sq___there gre Same Functions which _ pana rency — design at Foe just need to _ used those— functian. We don't have te Seg ony Fundion = fe Gym ea en in s@i.._over here. @e_yush ed nell what _action_has__to _ be done. We don't = have, +0 oor about the _ Ca@y—_W)@ _peo.g-__ i thor —acHon.. — | a oh ds _@ anis— ae as Compared +o = aie every easy tl Purpose “Lonquage = SQL? Why _do. we use it ?_ is 4 place Where We __ Store understand _SQ@L__ —TA “make. domain. specific “lang suage Q.. What—is— —! @. patabase - date. Database oh] __e To_interect or +e communicate. with. datebase we —_qlso___need__+a__talk _in_Some_ —tenguege _thob fs S@ * S@L is used: to noanahs the data. __* Using _s@___we Cori SQL is not _< there are __Pewn Tmoxt_—_gu eae a Which __are__fn___yesearth an. Few — languages. _qre= in used __— Like Be en, ail SOLserve , _PIS@L, Mys@L- sist PAS ACCESS. , ange DB. eine) 2 atebase — ST pes OF database — 4. FE Copp: pul es — ba — Datatypes og eansteatg Fy Software installation one _ 8 Basic __commands =_ = 9 Account Creatian ot = i oO Statements COT) —Overyiey Metis a at DQL 1a. Querie zy. Fun cian. ly A. sign menk 15 ueru 7 | id, Statement oe et 12 Normalization x Hisiory = © s@L was developed in. .1970__EF. CODD gp, was a mathematician had preposed ' mathematical model qed q__ fad tho cbe__con_—_be stored Tather. Raymond Boyce and Donald Chamberlin who where IBM researcher has imple- mented q_ came ._model. @_ “he initial. name was _SEQvEL_Cstmple English__quety lan uage] . Later name got chang ec} to” S@L_~CShuctured ques eh __becalse of Some ___traclemark up! $sues.. Uk based aircraft Company tease hae q__tademark. oF SEQUuEL__1 —wohy- the name -was changed. —____- @_In_1986 the _s@L__got_the _gobal__accepians --C-Everybody_Started._using _s@ pay 2 — —.@_1n 2016, sa get the recent updale—— e Jeo many Features cere added vome ~— OF the Featumts wert depricated Cxemanty 2 some of the. _ Features _coert modiFied- aX www. Taeboar wm] A bis \ sea i} 7 [es 1s pe Her thre Web servee | date win ~ | Bewveted)-[a0aq) | — Ee [Se] LJ aTorae| Jb: __..____ Presentation _ - Application, _ — ye —layer te layer to. at * As Database _testin = © Database __testin: is. vert important tshenant We __qre ae On__Some _SoFtwart. _* Database __te. ting has te be done in —— Fol.cwing. 0. Ss ee ~—O_ validate __the existance oF | oo Suppose iF we insert _ — data on the webpage and — = tthe _same__data, — should_ger_stered .in__database._once_ the dara ¢s store _ inthe database __ we neecl__ to. validate the presence. OF __the.data,.__ ae | @_ validate __ the correctance . OF date tn this we need fo-make_ Surt__the __| gota thot is Submitted on the Webpage __Should-—reFleck__as_-ik__18__im_the databing _ © _wolidate. “the. completeness of the data = =e —ea_should not be —aniy_loss oF 1—c}. ate in _tpe -database + Relrival :- amr is cess 0F Fecthing the aot hn even m__the — i — — data bose _ «Features oF sQl_ = oii 2 Sa GMy ational Database. —_ —inFormation. pate fs o—part_/ piece __ ——T_am__Pritee kawane © —Ll_am_ ee Engin eer. —_—_JName_>_Pritee kawane. Berinition = Data is q raw Eack which - oclescribe, the characteristics» oF an bpeck or entity DDitebose. = Database is a pl. Qce__cohert cr bere. the datg in a organixec| for iva —_____way__fer easy _retriva xD SMS (Datobase Pionegement - System ) || Definition = : tL DBMS__js_—_ SIN which is.. used te interact With the data Which store in datebase. For data Manipulation | using query language. —what__we interact = _ C= Coyote; OQ te = reo t operations / Mandpulaticn U_=_update. IS__stered in +erms of Flat P.._CSV —* Common _ Separgke _Vvelue f : = identify 2 thee alll data. 4 ae = RE: “Tea difFiculk ta [eliminate the). — Kanata awe] Normals cuton @ normalization is pat possible> tn. Dems. Ta. ee —we used spoma a __(Relationcy Database _ =e ement. system) _t ROMS it a IN__~ohich ts usec 7 inter ct coith the cata _ ste rec _clatabase For data manipulatio Rie Us iN. a —query_language / Relational model, J _ Advantages: Pic RDmMs o> @— 4 __ Eh ia 4 — = ce ts__q___Sma]|- unt} _of table 4 ___— Accounting rlumbal Rererien® Research pone @ mode p 3a1e3 pelhi “| operation Nordq —In__kOBMS data ___ has to __stored_tn_ _,—_—table__« oy. a oe 7 1 @ we can__store_ mult ple database. | @® The ce Ly “shouldbe atemic. I ca__cell hould. only contaIn onl value) _@_The table should Foi iow Relational mode} eae Category gn which date ey falls @ char — -@)__Yarehar varchar _2_ __@_Number - “char Cs Tze) #____ hor datatype —accepfs__size___as__fts___ argument. = Ee a i —— i ex. char (4) = [eee —, @__usin char type we Can store, sida = “ —O-= 7 o- 9 ——. ©The maximum size that char__ ——_Qtcepts_is 2000. 8%. thar__( 2000) oh orga @_ char _ts Fixed length __memory._allou! ——____|._ ‘There te Fe which = _t happen, ina char databype —s —Char_(lo) et _EFPERROGE used Memory —j——Memery used Unuse - _ ees waskajye 7 memory lear = 2 var een a - argument. ay F Tf ens varchar tS). —|— FEE my a ——-©_vsing__varchar we can ster a A-z - 7 Q- Z rh Dal o- 9g — - $$, @,4 1s 7 @_The maximum ize that varchar ~— datatype accepts is 2000. ——__ew._char (2000) —L char (1999 ) _ - —- fo. - ~~. @_1b ts pot Five co} length. noma arty. _* Allocation Tg te Tength memory —— Varchar 2. _ dataky pe accept siZe as its argue end __ bas ————-varchar_2. (4000) @_ apis not __piveol allocation _ n f thor (S$) vaschar (30) —_yarchara (ye) _vawher U8) fa empne ename ema}? conFath | = @ Aube i = - a I is ___useq|_ —he__stort__pumber_ values. Ls y niax —: Number_(_prec fst ont, scale] i Scale. i optional —t L Ln__ thf, we can aSS ant num a T number values as prect ton. aa ay - ease - 4 5. _ Number (Precision)... scale ¢ Nok prsent Case -2 +. Number (preci's fon cole) : Hii precisfon i> scale. Number (precision , .scale) iT Precision = scale. iG fo Enema cale Precision scale fs not present. at t x —s-. usecl also is_the la +2 ~ve. esk q_scal ee — 99-93 te bore wha)e (0,1,2-= in: Fegers —— block, 2 __ $99.99 “45.30 —4a.39 Number Ta, 7) - _ ee 7-82 Number (3,2) Case = 3 ‘ Number (Precision, scale) :.P=S number (3,3) __prebabilit -.9 4 4 : da | = 0-454 a (uu) | e $44 7 — 9.9aaq te + 0-9999 Case - 4 = Number (2/4) Operation. Scale — Precision ___ __In__above__case___ Result come: 5. sq __ 5 st xzere store in the block. Number (416) irate. . a4 49 Se ae | zl - _._ Reverse :-_ _ A i fT 0. 0000078 a oe ~ = Result = 5 ae = S- Pots 5 a -P=5 : @ Binary large. objec | oO heron e@. Object ~ce10B)> ee - _ ° gt. is similar to. Char null) — Not oul} =~ : TF__we give NOT nul! Constraints _ For~ Columns__thaf Columns wil! accephs _ any = value : a) -hle_con provide multiple. Constraint For a aluimns 3. _Check = = @_theck is an extra validation gin. any column = —-@__3F__the _conditian ts. true then $ then only the. teneittes data eosfl) £accepFec}____ otherwise _TE won't be. 7 accepted. . | Check Condition ) u -_ — — = o a ee i” ch iy) — - attributes | a+ Fey a em ; —_emnp—name. aglicu address Contack nest peau ———atebats—2ibiels er statu Cligible +o. become. _ (as) ission al rE mmi P imarrty ot - r T empno emp-name Sa] | corrtact | ____ + —chaaderistic oF primary ikey ae _ © se a coloumn is. made has 9 _ primary Ki then thak Coloumn. _ eS u crest duypli. core valy. (3+ is Sieg _ | @ 1f we make an i OA Ase qQ Primory ke then that. colam.n__ will] _ — not cept — null values (NOT Nutt). _ @ A table Can beve only one. — ces = Ga aie TE — © Fimory eee is__nor mandaiar _( buf oe it _is ~recommanded. as atid I Convection that +eble shoulol hay, / a Prima key) = a a ___| iby alo ae use primacy ay Li } OF tse te — ~ avoid ‘ety, Bie cab — {___cliate : Z __make__Colgum_ as Key @ deed primary “he selaile bee ween twa | _+han _+aro___ tables. @ if a Den é: ena.) 2 GS Fore'gn TTS eo lamMo can accepts nuit = LEG column 4 mace Fortig.n_ : hina Se ee t a Lt ot, not pnigse). _@ A Hple foreign. icy —. J reign i adlaterty unless > unti] Wwe want +o estebligh— th _ ~ _rtlatfonship _+botween the +able be primary Key PF table ~~ @ fp _table—_usbich__bosts Foreign key Can be calle ol —as__child_table._A__table_ ~~ __fram__which primary = is__cheaseQ____ ~~ a s__a__ ore jet 9 be ca}icof SL as__porent__ fable T | aR El tema afore ay 34 should | 7 commands — __@ crenr screen | cl SRE — ble tee. ee screen --e___clear_ oer | the to mae aoe _ an Hee screen, contest there the cuneate icor ne ame, i I @ 5 zs : a We use thi. cammancd to switeh — From Curxtnt account +e specific eT Ccotinikpe st ee at dyer a example — Connect Scott | conn scott — HI System —» scott = I coth ——» ystem it connected a i = I Show user st __# I __user__is Scote 3 7 e i H Select af [a — me Use this jab fo check the. “isk. = OF _+abl €5___present__tn__the _curnnt -account. _ | —connect ee « _ | Select _ | Pram___tob - “The stable coil be present. a —_ Ceo nen elect x From _tablename. The select is used +e display » a iS used for oll detetls J Select — frem___clept + eol__to the acount ___ table ts __jxtsenbe select eaecnsasaaae lpm Fable depts : a | a oe oD | Grade Dept nae Accountance Leo _york, 1 | ‘ wo : a Ss 3 7 neem & B ‘ ¢ ae s@u > desc dept “_ i = = = —|_Name. No 2 | —Type—— }— Dert_No | Not null] Number (2) DNAM ESE fe) —- | varthar 20k) | U2 /o Mea ps i varchar 2¢k) E k aes ALS lOc te command _we_will use to extend because the deRwt print_ay the line siZ€ Woes records. = TF by mistake wen “clear__the. a Creen anc _j@e «wank ~ previous, — command then use tL commong __ x How _te Create _new | ebser name. — eiger — Connected how user —» user fs System I @. syntan > getot_—_extate _setsion.. to 7 wn tsar, poe = —— a ej _ A ——+—-gca.m ple = grant __creake session —_ta_ ee O.micar; fa tt succes — a Be a it t 40.,_ bog nas. new __ 4 sen me | _————— —<—— = = _Connect___Omkar_ = omar}; _ > Connected Beh ey! Is shad users - - User is _omkar. oat @—Conn__system Z —. @)_ Create ___user_Pritee _tdentified bx. —____—+_User created © __Connect__mik" Pritee Apit+ Pritee -Connected). Error oil! occur 3- User Prites lace — faim Create _sossfon privilege; es Login. denieo) - = You 97800 longer Connected — ison grant creake session _ to yecitee ae : t__suceeedcleo}. k= | Conn__Prxitee ee pn —Priteet = — at Connected ye _ janet e Show user (ERSAn SO a ser _fs__Prifeei ei —Q—Data__petinition Language tapi) —__ OSes —Maniptuntinn —Languqge cea.) ——@_Data_contral__Language —Coct). ——-@_—data Query __longuage por) —__ ae Definition Language Copr) = == Ab empty table with ertein ~~ dei Columns _L_@__pewame := Ir is used ta chan 19.2 the name of the exis Hg = Peet stab] 2 to____new name. © acter += Q@ Aad a column Q@__celumn____ Ju) Delete Column, ——___ [tegen Datatype © change the “Gansta. a { is used 40 _clelete all jhe — 4 Truncate : cate oF the table bub the table. will not be arrected . we Structurt. Cannot __recover_ the truncatec) datg Seeeerenees |: Glang—__teith a] |__the date. Hem we —Can—_xecover _the crap _tublo. Re covering — Crop __table is possible along. with = it's __ date. ~ 4 Bate — Manipulation Lang fon Language = 7 INSeer a ; : UPDATE eee eee ~@ ZNSERT_ =» Th is used) te _insest_ the —_row_/_row's in +he +able- fanich alrenely Created, ___ update we use 42 update | i —2i__imad LF Q__partteutay rou or ous. clelete _all_the vows of q_ rt cular pads _ - permission. __ __| |@) -Revoke —> Take: ‘boric “the _pexinission ee te. —TFeansaction Contre] —Benguage ——_D_—Commit - _ aa O.soepeiot E fie cas - [ oe be —5—Dal_Cpasa—_Guery Language) = —__ @. Select — ® Proj ection “a_dause_ ne usec) ee ee ee 1a ie onthe —_oukpuk — soren LE serect—con nak she. exewted - 7 oo A I a u i Projection ==> — Proj ection —_is— used te display —q___ Park ler column or___multiple_ celunns rey __deractt—— a) thie. voles GE those “Liumns willbe wisp cae a eee eee eer sot ES dt __ hi. ~ hle use to _displa. _a)| the details —..____ oF _+he__4able “Fram __table— Nome; 4 1 - _ Select ge * Mt ‘ | _ _displo Frem table name + ee 7 — E-g __ Select —— ——From_—_adept + = emp =» _emp Hiredate = cal comm.,—__deptn. — = elect en, 7 = a - _—_—— 4 Pro rn. ~emp 5. sll sis res coedisplay. a — I Column. —_—_— q ‘Moke _sux__thar Colum pte fete H Present atin theese toh |e. sseeeesi pL How te dis play Pau lHple_ i. _| select ename, ToB, sa}. é Bem__omp j me = ee Distinct + vo x =e * —<__Distin wd }s__yseo) te Sy minntng tne —tiplieate values Ere the column — 4b _is__completely optional —___ elect distinct FoR Fram __emp + — Tos CLERK — ~~ ELLSMAN) —~___mMavacer —— a | ANALYST a aa | presapentice | —~_Lun@tp _the—solary — which ar sdeck aisHinch empidsenames « sa}, T°B om =! — Free mn ps —_Sa\— Tob Hieredate Lojooo | maanager | __12= Fea -1y, 20,006 — Salesman |— 14-Fan-13; _| 0,000 | anager |__ 14 -ApRei _Amor | 20,006 }— _Presiden}| 14 -JAn-~ _go,00o |. Salesman|—_12.- Fee~\ ___ Select _clistiner___ename, sa} ______frem_emp*, cs - —— ename sq. Ee = —______| | Mishq__}__10,0¢° Amar. 20,000 omar 49/000 7 a Select dfstinct ename sal, Foe 1 Sal JOB 19,000 | Manager, 20,000 | salesman __2OLCO CM Lc _ President _ i 49/0009 | salesman | s distinct sal ee ‘emp—>— |_| ename _| _—_ a ey, 0,000 mH proper -arpte— _ Amor. 20,006 | aS ed = Nishg 40,000 = = Amar ~~ | Expression. which means Omething oh ich 7 i give —a result. - — I Tt consisks of _operatens 5 well -_Opemand. - fe} _esyyt #0 o—— _ Result peanh— aoe Trer|=[aual table is q empty table] — ¥ Types _of Expressions = pis Tape © the value will be direct valu —_—_|_ _ 20.0 +300 —» $00 1 To asy a NEW Yorke |: 009.0. gperand. will be ow —T _ fam emp; _ Select _ename, sal 412 eee Fram_emp; Select sal _% 12 ___it _ TN AGTD Fh annued salary |_ename Sq) #12 | a — SMITH 9600 is athe ALLEN). 19200 . ARD 1006 ones 34200 MARTIN 294 09 BLAKE 36000 CLARK 60,000 | x -WA@TD the name $ the of _the. = employees aFter 30% of hike a ename al ol + sal * Boljo | | al +a] 4 0-3 ag Allen Loo loot loo® 03 = [bo | Blare Zooin. | ago 41 | fs core goo | ago | cmailler | goo | _ _s20 - - smith suo t GSO | a : + —_t—__— = 4 q @. Beth the operands gx Columns = Selec Sal + —i Rem —€.20 ps. comm. é 7 sumber daraty Pe 2 : _ sal i “comm: Sal+ Comm | __}t —}— op - lo | __ 200 — 200 i Boo | = Poor — —$90in1 f a Yoo - S00 = _— a SS 2f2 — boo MOICie es) eae oe ¢ Alas Name == = _ »——_|_= select -sol x [ a le Select sal * Ja || Be. m__emp ! / 2 : “Alias name is @olternati., nome —— __gitin__fer aq column — or an expression, Ss Qnnual sa) —key-coord__is__ optional, When _we pi Be eaeenes nents nT enaEITRSTnEEETOEET alias Hame. ——E-g -Se@kd_sql «12 annual — sal “This quer Will Dot work p thraces error ike “pam Ke ytoord__nok Founel pecte a a TP we __want +o provide Space. ir +he- ————alias—_namz___me should _q__qet execute the query by providing Alias name within [| elouble ques 7 elect sq] 4 19 A qonud) sal Prem__emp —-

You might also like