Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
248 views29 pages

Dbms Notes Unit2

Uploaded by

Naresh Babu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
248 views29 pages

Dbms Notes Unit2

Uploaded by

Naresh Babu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 29
ae ae UNIT-2(f) mtn sae: Maggt [ | The E/R Models § — E/R model stands: tat. “ath Entity Relation ship Model. gt $s 4 high - level data model. “SThis wmode) Se qivied to define: tne dale elements, dusd!! isielaonshiy for a It also derdop a very cimple and ety Jo design view of dota. | Hit df >In ER werteting, the database struclure is + \ sepfecented o4 0 dliggiam called, an E-R clea: foy evamiler Suppose we design 0 schocl daJabate .In thir’ database, the ‘cludewt will bo an entity usilh adtitbula hee oddvers, name, td age ele Chame > 2 were of E- ea a Enhity Adtribudes! ‘Relation ‘ [Hkely Atibutes. | | Che teak Erg eieudy {re Pte _ p-Carratie Attibubes Lote L_NjultiValued Attalbutey my L_jerived Attsibubey Many focte: t- Mary faa 4Enti +> An Entity Poouy be any object, Clay, pertan or place. > 4m the ER diagvam, an entity ca» be, yepresepled ag Heclang les : Contidey ap, orgorisatdon as an eqaptle- noragey, product, employee} department cle can be feben a an ebtity . a ae Deparfment Ge eee eto ce a) Weak. Enti i =p, entity thal depends oh another eokiy $s Called as Weak entity. : The Weak entity doesn't contain ony fey attribute of 3c own. >This 4¢ SHep verented by double ie ange 2-AHibule s — YThe attyibute as defined ured to dere- ibe the properly of an entity. Eclipse 2 uted, fo Gepresent an att ibute- ne WI For evample, tds age, contact numbers name ele ca be ed attributes of a shudept. eae Atlvibute 8 —— oy key odtvibube 34 wed +9 ey esent the main chovacterisHee of a, entity. ; ST} siepresent ‘a pripayy Fey. —> They Fey ctaibute 25 Sep (eng by on adltce with the text wnderig b) Corpsite Avabule? — An oltsibute that corm paced ot any ather atsibube as khowh of a compile | attebubes wjepresepted by ellipse, and | Ths <\ljpces are connected with thos < an ellipse c. Mullivelued Attributes | An attribute can have move than one | value, if khowh at multivalued attsibute, ~The double oval 3: used fo sepresent mull valued AHribike. For encumle, a tluden} can hove move than OMe _ phowe numbers! trades “de Jerived Attribute i : . i "S'An atiribute that can be derived fom athev attribule © 3s known af a dovived atteibuk Lge qo arepresented® by a duished’ et\inse. oy endsple, 4 percan's age changes “over He abd can be derived fram anrthey atfribule jike-— Date, of Bisth- ' Care | student. Bi} Cage 3-Detationship® | op sh stelationship 35 Wed” fo deserthe 4, Dlelation between enter “SFiawmond or shombu SM wsed fo epee the sielation chip. Ho | a ig 1 Saoh ey 7—|ruden | Tapes: me a One-to-one Delationchip * = alhen only ove insfance, of an ek u , associated — wilh, the smelatonshig, thon if ig Known as —ohe to one | Giglationships Por, examples — A. Peroele cay marry {om tmale, cre 4 male Cap marry to ohe rd wont [Female e artied Py>— "jhe | @-ohe- to-mony Helahorships — —>Ialhen only one inclaree of am entily ont left, and move hah “ohe inslanco ofan evity on the MUGh atioclaked ath orelationchip then Hig Fo- many elation chip. Wo Rhowh oy a ohey | on invention i Aone 4 the only spe- For enample, scientist ‘can einvent Imari) & buy the invencion cific selentist. § 7 a invents [invention OMany ~to- one Helakionchips — >IWhen move than one initanee.of an entity a the Jet, ond only one ingfance of ab onltpon , oul Wt aslociote: with “tHe wieladiahchip ted tf fs “Known at many—to-ohe sielalonship- Por example students eprote for only > phe Coury, but & cource can hove Many students. My de rary 4o a srelabonshie! —syjhon move Fhan one, inctarce. of the eph on the left, ahd more than one \nstounce of +Hreanentiy on the souight assog— ates with the stetabionchig then it it known od many-to-many delationchip. Poy examples Empiiyes can assigh by Many PrD- Jjeckt and project cn howe many employ ect a mega Y¥Nolation of ER ciagraD? —— " 4 | = Dalakase | can be ae sig, Sho te Pons. In ER Aiagrary mony nolahon are os 4o eopress the cardinality. ose oes Obe to one | 1 i ope fo mang{mandalory) ; ; Pmany fe bre. a Fone or Moret mandatory) one andonly one (Pandadory OT Serd Or ohe Cophonal) 7 zevo of many CopHonal) The Lelatfivhal pce 8 — 4 _sPelational model can represent as: a fabh with | coluveing and” ‘yous. Esch ro is known as tuple, Fach table, gf the column hay a, nougel ottibude, , aly x domain: — 3H confairs o seh of atomic value’ that an attribute cab dake. : aeAffciburte $ >H contain fhe hame of a col : porttulay table. nT —- ach ott tute Ai must hove a do 0 dors (Ai). lores ? ee Relational inshoneet —_ i 750 Abe selational dlajahaye satlen, Ve" elation oA inctance ar wiepresented Py 0 Linite cot of tulle — Pelotional Vottanees oe Pot have duplicate fuples. beatae ¥Qelat ional schemas am : sa s ‘stelakioal, schema scantosa! the name of” the! Yelallip and” name of ‘all column or gHyibube - Aletabom) keys tala) PID the. Melational tare each row hos one oy more attribute. $4 cap Adentity , the , mu in He. relation un iq 4g Ny. Erumyle: STODENT — Re} akon NANE QOLL-ND = PHONE NO A DDRELS AGE Paws ( (A195 TB0dEG8q00 | Noida 54 Shyars (6c6d 902694934n Delhi 3 Loxmen 93264 cee Gurugam 20 Mohah 118] CoovooddC0D Ghailad 27 Sprah (1282 Bot gaesso Darhi | 140 fo®h the given fable, NAME , OLL-NID, PHONE NAO and ASE cue the ollstbuley ® The inance: of chema | oTyeNT has 5 tupler 8 B=< Laxman, $9209, 3503 Ye 7162, Gurugiam, 20> — — Jearertion of Letahons: eName of the welaton is dich nel Fro ay other Gielotions. ae «Lach | delaHon coll contains exactly one adtrnict single) value, bn ‘ *Each attribuke obtains a olwtinel NOums tAtiikute domain har no significa Relatonadl language. J} x "alts khowh a4 declovahve caleuleés is a hoh--procédural quey leegie ect all relational ofe- Telahiona) caleutey, Ft 8s mostly nprobecnres by the eng User¢- — 44 LC considered ge QO User longuage. +3 The level ofs Abdvaghon iy bigh. —S The, sielatonal Caloulus +fel}s eghat jo do but never explains how ty oo, >It is possible 4p enpy bra queries into frierd lly ae eae “Types of Relational colculurs RelaHonal Calculus ‘ 4 (jin 4 j T “Td ple Pelotiona i Pech Pe leona Calculus Calcultis ATuple Qetational Caleului'(Tec) : — fe —>The tuple ‘stelationa| Colculus is specified fo The siecult of the “seloken coun hove One Ot more -fupler. Notation: — ETIPCO oy {Tlcondition()) \Alhere T isthe sreculting tuphe | f PT) is the condition tured to fetch T: ov example : — {Tv rane Author (1) AND T.arkele = dado baie! } outpuds— Thc query selects the tuples from The AUTHOR pie TH stebarne 2 ‘title oll troumer tro coho _hy eae” RTOS - on ‘database'. j Tee (tuple velation calcul) con be quantifieg, Tp TPC, We Can use Exictentiol (J) Ghd Unteny Quantifter (v)- For example LQ\ SITES Authow (Tavticle ='dafaboue' AND rane =T. pore)? output —— Same yerat ay whe abiye) — 9. Domain Relobianal Codoul (eos — bk sThe-., cecondl sform, of sieleubton is king ‘as Domain sictakona! calculus. —5Py Gowain srolatonal ..cofculus,- fulteri variable user the dlomain.of atbibider —> Dopalb Gelotonal calculus , use. the om operators as tuple calculus, —> Tt uses Iggica comhectiver Acana), Va ord 7 tol). i —» T+ uses Existential (@) and universa} Cue hihiers Cv) to bind the Variable. Notation: — {o1,02,03, -.,an|p (002,03, -__,an)7 talhere |i alja2 ave attribubes is DP cteencls boy formu ule, beri} by inber cxt}rt ti | Poy examples — mooie rh | {carticle, page, subjects |e Jowvotpoiit a subject ='datatd 4 outputs This query voll yeld the’ drlele, page, ard subject from the relatiovial jovtp- int, wheve the subject 2 0 clatabate, H§nhoduction 4o Database Design: — | >Database design is the oigarizaction of dab according 4o a database model. : —> The designer determines what, dlato put be ctored and how the dato elomentr inte. yyelate- i : | —databare ', desig inuo|ver classifying alata and identifyjng inteyyelationships. Ly the theoretical repsesentotop of He cet fs called ah, omtolog y. Tre ontolegy ts the theory behind the clectabose'e design HTK Yelattonal wih 4) ; elanony Njode| Dn ely, Consteay Over “Qeladtors’@—— ts , > Integrity constraints axe a set of suley, E54} Gs used to paibtaln the qualidy ot ifr: mation: —>Jnlegrity conttsainks enure that the dala intortion, Updating, asd other . processes hove to be performed in such a way thot data 2nfe gry is pot affected. Tu, integrity conctraint is used +0 gees aint accidental , damage 4p the dataha Types of Ontegeily Conitsaint 4, dowaiy Constsaint ‘ | 9. Ewlity Potegrily Constaaint Be Relential Teg rily Cort gaint A key conitr aint: 4. Domain Constsaint 2 —— 5 Dopain Constraint can he defined ot Lhe definition of a valid set of value fr an attribute, —sThe dato type of domain include se 095 chavacter, integer, time, date, currency ete The value of atte : ibute i Fore, See ay cide meat be onl FE Exg— Fa gg 5 ty Nome | 1 “semetter 1 =: tooo | om |) ast [1001 | Johbson Sand : Pipa Ieonardort — 2a | 1003) ee | Lio n4 Morgan eth Not alolbed 5 Mepaied AGE is an integer attribute, Entity integriby Conttyaints The, entity iphegrity | con traunt slater hab - peer Fey value dant} be pull: SThi 9 because the primar key value it used +o identify jpdividual yout in velabton anf Vg whe primary key hog a null value, then we can't idenhty Hhore rat i ok table cap contain a null value ofher ey ‘ tran the primory k ra field Enarsple —— ooo PF Emptp EMP-NANE |! SALARY i 125 Joo a00000 | V8.3 Harry GO0000, | 164 Jonw ZoOVOO oh 770000 col | fl Nof atloured cr Geinery bey can't coofain a NULLValue 3 deferential Ineqridy Coneteaitts 7 — >A sielerenttal jotegr conshaint #4 specified belween tse feo. Sn He Referertal inteqeily contain ® Sveign key in ‘Table cefert te the 4, ry key of TTeble 25 then every value dhe Foreign key iD “Table 1 must be buy or be available io Table» Examle — ®pletr EMP_NAME| NAMe | AQE t \ Jock 2 Hawry Ss Toln 4 Devil Primaxt, \ | 4key constraintss, / shes che the entity cet trot ts, use identify on entity within ih epkly Se} + entity cet tan have wulligle 4 but out of which one key Laill be the Oa oe A grmay Fey Can contain o anc null value in the velakonal dahl ' i \ quot at lowes - decane. all row mut be Bnique 1 +r Relational Algebra ere —= Relational algebra Wa groceduro epee cuguage, = $t gue o step ty vesulf of Query, > Jt ayy opera ito per brs acta Ty pes of-sfetelonal operacton : — Lelalienol Cpesation 1Selec} Operation : — The Sk ds denched by cuppue there. ase two tuples Qs. The Upton operaliah confaint all the 4upler that ane either in Ror cor both in Qa, St eliminate: Jhe duplicate: tuples. 94 is deno-| ted by OU. | Nolotion: 2 ul. A union operation, mus holel the fy 7" I Condition vy Rds much, have the offributey of the ‘Oe number - ' «Dupliccee tupler ager eliminateg automa, Uy : Exanfle Depostroe RELATION CUSTOMER NAME ACCOUNT. NO, : Johnow 4 } 18 lol ; smith A-l2t i Mayes rt B32) IMAM Turner a BORROW RELATION CUSTOMER NAME) S LOAN_No Jone i ot Syith ; ae Hayes re TTatkson : a Qnput — 7 TY CUCTOMER_NAME (Boeeot)' UT curremeR NAH outrut cuttimer—hame Johnson smth Hoye Jarner tL 4). cet Interoclton ? — — > supas there are tio tuples Oi'¢ The set Intersection opetahion - confaint or tuples. : ne S416 denoted by! 0. Notahion: @ ne Ero0ur9 pe — Using abuve pe ror sued Bonney ‘put — TT CUOSTOMER_NAME (BopeuWi) 0,1] CuSTaMEe NAME , Owl pal —' CUSTOMEE. NAME Leth | { Be Set Difference : — > Suppote there asic froo- feepler! RPh. DThe set ,irtexaghon operalion, Gontgint al tuples hot are io & but nok in & > Tf ic denated by Intersection rrinus (>). Noteton: QS | Erample 3 sing 4 +he cbove Depo Ww fable, Mput? \ i Tl customee NAME (AoeeoIt)- FT COLTON oth Cusfower— NAME Jatt son Heyes. ear0Q fable Levee. ee name (Derr TOR 6. Carte sian Psoduct ¢ — E “The cartesian procluct is used to Ch, “each YOW inh Ohe fable with eaah my the othev fables Tb ic alto Khowh as a crots produck y © hE ic denoted by ®- 3 Notations Ex Dd . ' Example? — . , ENiptoyee ; : Empey) MPD NAME) Ex. Deer, 1 Smith e » Heury a g John hi DePAPT MENT Pe oy DEoT NO DePT Lae © | a Wer eeting 7 hh ee hay it MOR on _ Legal Yount — f EMPLOYEE ©) EoRET MEAT outpud — Th g.dename Oporotions —r “sThe stehame . opexatron i¢ wed fo rename. iS output srolabion. St alenotoa by shal py. eri sa STUDENT —5 STUDENT! P [crupeng 4, STUDENT), oe fist pea AJoins + ae SA Jjeip operation combines elated tule Aron different iojelatons, iL and only if agi join cobdifin ts cadicfier | ; | 59} 8s dlenotecl by Example —— Employed? EMIP_cop9E EMP. NAME ol Stephon PoUrntos ' Mack 103 Horry SALARY EMIP_ cade IOALARY lot 50000 tor : 9900 m 10 95000 , ‘ ' operations (EMPLOYER 0 SALARY) Qecult:— EMP code EMP_N Awe SALARY lo} Stephan 50000 vor Tooke 32000 03 z (OG. Horry 95000 Se Types et! _foin operoHon § "Join oporaton eto ! ees Notural Soin otter fib! Cee L Lett Outer fein, i ty Rian outer Join i r L- Full ottterTotn Ay Nodusral Soin ce >A Notuval - join’ isthe, seb of decples af atl combination in Land t that ame equl on theiy commn attribube pames,- hs Gistc dengled by x. Erample —— 4 Lets use the above EMPLOYEE fable cing SMa 4oble. Poput — TIEMP_ NIKMEs SRLARY (EMPLOYEE 0a SALARY) oudeu) — » EMP_NAME SALARY Stephon 50000 Rou 3000. Rou 95000 } i i 2.Outey pins — a The oubey join Ha oporali of the join vparbinc thor San) exh ey! \nfotinatty, St is cued 40 deal wath wisi Exam ple — . : EMPLOYEE a FACT_Workers \ EMPNAwE RAN Shyaw) uber, CEN ad Doped: bE ae (ErapLoves o FACT Woekewy) | ‘ ouput s ' CMPNAME STREET «CITY BRANCH RAN Civil tine “Munda; Dnfoeyt ‘119000 Shyam Porbitreet fcoltale wipro; ,, 28290 Nebyuragay Hydeithay TCs 50000 SALARY Hori dele g bRight caer joins iat An oulesy join ix bauically of i ig type DLef} outer join ' 4) Right oulen (join D Fall outer Join : Parasite gyLet¥! outer Join’ Left outer join confains the seh a tuple of all eombinahion sin Lands tha auc ay oh Theiv commen attribute Paes. 1 — >In ther left cube join, tuple in ea 1) makching ‘fugly ins: > ‘Ih is’ denoted’ by m4) Boaipple— using, the above, fable’ ¢ Cetenvee table and PACT WoPKERS able. Spud — t EMP NAME; sTRECT [CITY |goAncH 7 cALARe Lam Qivilline | Muwbal| Prout | 10009 | Shyoum __| Port cred | tattle Wier | 20008 Hout Nebtu Se Hyplerada) Tes Sooo | Row! M. aimed rl ‘| Nutt ALL | — Right ower oib contains the cof of of all combination inp ani a Hel OF + equol On ely COPD OH attibube paw ofp wight outer join, Augler ip Shen con ping: tuples tp vrs rer coins dersted oy" DC. vi he Example — Using the a Erartoyee fable, and Racial oneey Lelahon. yin Qrqutt$— 7 EMPLOYEE MC FACT_Woe Kees sie outputs =o road ann oi Ht EMRNAME. BRANCH nSALAN TLE i chity Rom Tfosys 10009. civil tine ; Muabad Shy Wipro 20000!) Park Street / leoleale Hari Tes 50000 Nebsu threo}; Hyderabad kuber Het — 30000 NULL) tat, Full outey joins — 7 Full outer join ts like: o'taft os ight Join exceg tod st contains all youre trom both! ley. In full owlers join, duples tm @ that ‘howe ho Wachig dupe, Ine’ and uplec ip & that have no Mathing iQ ih their Common attvibuber Nome, — V4 a deboted: by ne Eortle — Using 4he above EMpLover fable and FAact.workent table, Xopud — h [EMPLOYER XE FACT. Work ees a oa ‘utpel —s, 1 ’ ha EMPNAME = STREET TTY ~'GPANCH | CALAeN Ram Oivil Nine. Maeuma! Infosys 10800 _ Chypue Payt street oltata wipro 9.9000 Haut!” qrobny ctreet Hyderald’ C8 goo 00 Ravi Wg.ctree} Delhiy voit > | Not Kubey = NULL = NLL“ 20.00 yt SEqui join: id 5} ic alto known as an inner” on. 94 is tho moth comiseb! Jone >Hi 'Balsed) ph | madched’ data vac ‘| ely 1 ae nin 5 The" equa join user "Lhe compari dpevatortd). Exaxenple —— M3} : Ws CUSTOMER RELATION! 0 Tu cuts DDS 4 NAME ae ty Hpdh dat cohob Raley x iy i thijan i } i © 1 Mo haps PRowey e vet _1) city 9 Sethi ; 3 4 baj Froud: Neva OMOMER % PPOpDeT ouctpr| — » ey NAME PeopucT ID osty Delhi s 8 Mun bal if . Lor do, =

You might also like