DBMS QB With Solution

You might also like

Download as pdf
Download as pdf
You are on page 1of 14
1 10. 1 VTU.REG.NO I 1641357 5 BLE, Fifth Semester Examination — September 2023 (Summer Term) Database Management System Time: 3 hrs] [Maximum Marks: 100 Note: Answer any FIVE fall questions, selecting atleast ONE full question from each module. a) b) °) a) b) 9 a) b) a) d) °) a) b) °) a) v) °) a) b) °) a) bv) °) a) b) °) a) b) Modul Describe the characteristics of the database approach, (07 Marks) ‘What are the advantages of using the database approach compared to file processing system? (07 Maris) Ilustrate with neat sketch 3 schema architecture. (06 Marks) Design ER diagram for company database. (07 Marks) Ulustrate with an example specialization and generalization. eis) Ilustrate different types of relational model constraints with example. (07 Marks) Module - 11 Discuss SQL role, features and benefits in detail. (0 Marks) With neat diagram explain centralized and file server architecture. (QO Marks) Illustrate with an example DDL statements and DML statements. (06 Marks) Ilustrate simple joins and join with row selection criteria and non equi joins with an examples. (07 Marks) Demonstrate Aggregate function in SQL with an example. (07 Marks) Module - 1 Design and explain steps for informal design guidelines for relation schemes. (07 Marks) Explain Inference rules for functional dependencies. (06 Marks) ‘Why Normalization is needed? Tlustrate with an example INF, 2NF and 3NF. (07 Marks) Develop an algorithm for testing for lossless join property. (08 Marks) Ilustrate the problems with null values and dangling tuples. (05 Marks) Explain 4NF and SNF with an example. (07 Marks) Module -IV Sketch state transition diagram illustrating the states for transaction executions. Briefly _ explain it. (06 Marks) Describe the properties of transaction. (06 Marks) What are the characterizing schedules based on serializability. Explain it. (08 Marks) Develop an algorithm for two phase locking techniques in concurrency control and explain the same with an example. (08 Marks) Develop an algorithm for time stamp based concurrency control, (06 Marks) Explain Granularity of data items and multiple Granularity lo (06 Marks) Module-V Develop an algorithm for Recovery techniques based on Immediate update with respect to single user and concurrent. (08 Marks) Develop and explain Aries Recovery algorithm (07 Marks) Describe shadow paging with neat diagram (05 Marks Explain types of security issues, threats to database and its counter measures, (Qo Marks) Explain Discretionary access control privileges. Go Marks) Dethase Manag cmet- ey Selene 4 hi l4csoa, Qi a Characteristics of the Database Approach LA ‘* Self-describing nature of a database system We Insulation between programs and data © Data Abstraction * Support of multiple views of the data * Sharing of data and multi-user transaction processing | oh s Kst- ele aaa Enplam 1 Advantages of Using the Database Approach ™ Controlling redundancy in data storage and in development and maintenance efforts. Sharing of data among multiple users, ™ Restricting unauthorized access to data. Providing persistent storage for program Objects In Object-oriented DBMSs : Providing Storage Strctures (indexes) foreficient Query Processing Providing backup and recovery servi a Providing multiple interfaces to diffe (oawabgny Crics>— aU @ Figure 4.3 Generalization, (a) Two entity types, CAR and TRUCK (©) Generalizing CAR and TRUCK into the superclass VEHICLE. 26) Constraints are conditions that must hold on all valid relation states. M There are three main types of constraints in the relational model: Key constraints Lede (Mert Entity integrity constraints ‘™ Referential integrity Bometalaia so \ . implici int is the domain constraint Ke ane eeyynielec tans must be from the domain of its attribute (or it could be null, if allowed for that attribute) ‘eset a database management sYStem, Or is ita stand-alone produc “ipuy SQL." Instead, SQL is an integral. The database engine j ually structuring, storing, and retrieving the data in the : 1e her DBMS components, such as a forms facility, report write, raccepts on ran application programs, and even from other computer ive query facility, rs type SQL commands into an interactive SQL pre ‘an interactive query !anguaée a ing @ convenient, easy-to-use tool for ad hres jata and display itontl al retrieve queries. language. Programmers embed SQL commands into their applica ; ramming fang pplication ard eee he data ina database. Both user-written programs and database utility programs programs to acces: tools) use this technique for database access. iters and data entry for OS al Sa guage. The database administrator responsible for managing a i administration lang mi Ce eter Jatabave uses SQL to define the database structure and control access to 3 cent n ain a the store ent/erver language. Personal computer programs use SQL to cornimunicate over a network with database servers that store ‘shared data. This client/server architecture has become very popular for enterprise-class applications. ore eon nternet data access language. Internet web servers that interact with corporate data and Internet applications servers all use SQL as a standard language for accessing corporate databases. + SQLis a distributed database language. Distributed database management systems use SQL to help distribute data across many connected computer systems. The DBMS software on each system uses SQL fo communicate with the other systems, sending requests for data access. = SQL is a database gateway language. In a computer network with a mix of different DBMS products, SQLis often used in a gateway that allows one brand of DBMS to communicate with another brand. SQL has thus emerged as a useful, powerful tool for linking people, computer programs, and computer systems to the data stored ina relational database. arts 3b)Network Architectures — 2 ts le & G2 eta Centralized Architecture ‘The traditional database architecture used by DB2, SQL/DS, and the original minicomputer databases such as Oracle and ingress shown in Figure 3-2. n this architecture the DBMS and the physical data both reside on a central minicomputer or mainframe system, along with the application program that @ accepts input from the user's terminal and displays data on the user's screen. The application program communicates with the DBMS using SQL. Suppose that the user types a query that requires 2 sequential search ofa database, suchas a request to find the average amount of ‘merchandise of all orders. The DBMS recelves the query, scans through the database fetching each record of data from the disk, calculates the average, and displays the result onthe terminal screen, Both the application processing fact, all kinds of Gua ien onl on the central computer, so execution of this type ‘of query (and in i ficient. pita: terror “The Introduction of personal computers and local area networks led to he running on a: flats server architecture, shown in Figure 3-3. In this architecture, an application ad computer ean transparently access data located on a file server, WBICN Ste : ication re king software automatically retrieves quests data from a shared file, the networking eves the requested Bock ofthe fle from he server Early PC databases, such as BASE 3) So Microsoft's Acc th Shand ce copy ote Reece ported this fle server approach, with each personal eOMPNTT fanning heh 600000.00 CITY NAME ‘TITLE Chicago Bob Smith Sales Mer ames Los Angeles Larry Fitch Sales Mgr ‘Non-Equi Joins The term join applies to any query that combines data from two tables by comparing the values ina pair of columns from the tables. Although join based on equality between matching columns (equi-joins) are by far the most common joins, SQL also allows you to join tables based on other Mery comparison operators, Here's an example where a greater than (>) comparison testis used as the basis for a join: List all combinations of salespeople and offices where the salesperson’s quota is more than the office's target. SELECT NAME, QUOTA, CITY, TARGET FROM SALESREPS, OFFICES - 111 - WHERE QUOTA > TARGET NAME — QUOTA CITY TARGET Bill Adams $350,000.00 Denver $300,000.00 Sue Smith $350,000.00 Denver $300,000.00 Larry Fitch $350,000.00 Denver $300,000.00 ¥ , conics Kish VON paceght Aveo arplemhe TO MINO AS teri a Lisl col (Maru for relation schemas al guidelin ition Attributes aa Qsayinformal g sna ofthe Reon in Tuples and Update Anomali m Redunc Null Values in Tuples wm _ Spurious ty, each ple in relation should preset one entity or elatcnship EL iconv ‘ons and their attributes). ote (Applies to individu es (EMPLOYEES, DEPARTMENTS, PROTECTS) should no Attributes o i xed i relation i . ve ign ey oud ‘be used to refer to other entities Entity and relationship attributes should be kept apart as much as possible, it sidelines gn joes not suffer from the insertion, deletion and update ano 7 .-Desgn 9s a pesent thn note them so that applications ean be mate take them into account nor Relaons shouldbe designed such that their tuples will have as few NULL values as sible . i ws Retbuts tat are NULL fequently could be placed in separate relations (with the | primary key) ie 1 Crrdeline Reasons for nulls: Cu @ Attribute not applicable or invalid lowe M Attribute value unknown (may exist) Value known to exist, but unavailable ™ GUIDELINE 4: '™ The relations should be designed to satisfy the lossless join condition. No spurious tuples should be generated by doing a natural-join of any relations 5b) Inference rules for functional dependencies IRI. Reflexive) If Y subset-of X, then X > Y IR2. (Augmentation) IfX ne XZ>¥Z enh (Melt M_ Notation: XZ stands for X UZ) IR3. (Trans ive) IFX-> Y and Y>X>Z {x626M Decomposition: If X > YZ, then X > ¥ and X > Zz Union: IfX > Y and X > 2, then X > YZ Psuedotransitivity: If X > Y and WY -> Z, then WX > Z, 5.) Normalization i normali is technique for organizing deta . : to mini Ing data in a database. Itis important that a database is elo prevents ne eney (uplicate data) and to ensure only related data is stored in] [6 ‘eletions, and updates, SS48S stemming from database modificaione such o¢ reertery First Normal Form FirstNormal Form Disallows composite attributes M multivalued attributes ™ nested relations; attri ations; attributes whose values for an individual tuple are non-atomic wah ancP taplesnsiie ou. tae eat ane 4 2NEA relation schema R isin secong tional econd no p Fietionally dependent on the primary por form NR) ifevery non-prime attribute A in Ris fully BNF: Transitive Snr: functional d Bauiple” X>Yand ys z'™ “ependency: a FD x > z that can be derived from two SSN > DMGRSSN is a transitive FED Since SSN-> DNUMEE SSN-> ENAME is nonvranting SOMBER > DMGRSSN old Since there is nose of atibutes X where SSN > X and X > ENAME 6a) Algorithm : Testing for Lossless Join Property universal relatic iti LC functional dependencies, R, a decomposition D = (R1, R2, .., Rm} of R, and aset F of - ae an initial matrix 8 with one row i for each telation Ri in D, and one column j for each attribute ij for all matrix entr ij is a dist i i i) 3. Poreach ow i eiposenni cis ach 8a distinc symbol associated with indices (i) {for each column j representing atibute Aj {if (relation Ri includes attribute Aj) then set S( ( each aj isa distinct symbol associated with index () *) 4 Repeat the following loop until a complete loop execution results in no changes to$ {for each functional dependency X >Y in F {forall rows in which have the same symbols inthe columns corresponding to | attributes in X {make the symbols in each column that correspond to an attribute in Y be the | ‘same in all these rows as follows: | If any of the rows has an “a” symbol for the. column, set the other rows to that same “a” symbol in the column. Ifno.“a” symbol exists forthe attribute in any of the rows, choose one ofthe “b" symbols that appear in one of the rows for the attribute and set the other rows to that same “b” symbol in the column ;}; bh 5. Ifa row is made up entirely of “a” symbols, then the decomposition has the losslessjoin gM, property; otherwise it does not. 6b) problem with null values and Dangling’ ‘tuples A tuple with a foreign key value that does not appear In the referenced relation is said to be a gnplawlin deh Ener pi OM dangling tuple i includes funeti dependencies F (that ine! ead jsil F with res} ect to a set of e 0 e un ! Am tea sp priialmlvaed depenceny pated idencies and m Itivaluc a \ em uperkey for a mat form (SNF) (oF Brajest-tn Normal Form “7.4 ia Fe ene in A if 3 XF)) wi of functional, i, and j ddencies Can three ae pendency DCR, Ras Fs) i ihat i, implied by F), £5 42.7 for every Ty Ris asuperkey of R era os ery ike TH 7a) state transition 4883 te it End m Begin { . Commit : Geiss) Pariially committed Somat Committed) transaction Figure 174 ‘Abort Abort State transition dia gram illustrating the ei ee eee C states for transaction execution. action execution. the database items that are tion: This marks the beginning of trans m begin_transact ir read or write: These specify read or write 0] executed as part of a transaction. mend transaction: This specifies that read and write transaction opt and marks the end limit of transaction execution. ‘At this point it may be necessary to check whether the changes intro permanently applied tothe database or whether the transaction has to be concurrency control or for some other reason ie commit. transaction: This signals a successful end of the transaction so that any changes (updates) executed by the transaction can be safely committed to the database and will not be undone. a rollback (or abort): This signals thatthe transaction has ended unsuccessfully, so that ay changes or effects thatthe transaction may have applied to the database must be undone. Mundo: Similar to rollback except that it applies to a single operation rather than toa whole transaction. = pees This specifies that certain transaction operations must be redone to ensure ‘that all operations of a committed transaction have been applied successfully to the database. 7b) Desirable properties of transacti prem nsaction perations on erations have ended duced by the transaction can be aborted because it violates e aoa ion is an atomic unit of processing; it is either performed in its entirety or Consistency preservation: A correct execuli papeeeeth cieahigets come execution of the transactiun must take the database from Isolation: i \ Folaton: A a should ot make i updates visible to oer transactions wil is it ; ic : cesang rollbacks of transactions MaRS Gee Chee ee Daraily or permaneney: Once a transaction changes the database and the changes are \ges must never be lost because of subsequent failure. 2 Lin . anv de. Vs ak + ereeate (es Fae 7e)Charaeterizing Sched Serial schedule Ped on Scriaiabitty Serializable sched) Result equivalents ae i ee Conflict equivalent: Sean eee Conflict serializable ale lsonca Fs Q8a)Two phase locking tech To Phases "CHM nconurreney contol Algorithm B (a) Locking (Growing) = A Merl (0) Unlocking (Shrinking), — & movie, % Locking (Growing) Phase: A transaction applies | it i : ¢ Unlocking (Shei Pes lacs (ad or wrt) on desired dts items one aa ine A transaction unlocks its locked data item: i c 8 one at a time, ™ Two-Phase Locking Techniques: The algorithm ee = R Ht Tead_lock (Y); read_lock (X); Initial values: X=20; Y-30 read_item (¥); read_item(X); Result of serial execution unlock (¥); unlock (X); |’ TI followed by T2 ‘write_lock (X); ‘Write lock (¥); X=50, Y=80. read_item (X); Result of serial execution x T2 followed by T1 X=70, Y=50 ‘Two-Phase Locking Techniques: The algorithm TL 12 ae = ; X=50; Y=! poten oy Nonserializable because it. unlock (Y); violated two-phase policy. 6 read_lock (X); read_item (X); unlock (X); ite lock (i read_item (¥); Y=K+Y; write_item (¥); unlock (¥); ‘write_lock (X); read_item (X); LSX+Y; ae OO unlock (X); 8b) Timestamp based concurrency control algorithm Basic Timestamp oy eseues a write item(X) operation: 1. Transaction T issue ounger transaction ‘the operation. sk) > TSCM, then 2 ¥ of T and set L-back T and reject rite_item(X) of ee te > TS(T) oF if write ea eed the data item s0 abot so a arity contin jn part (a) does not exist, ansaction has already written to the Peind reject the operation. H-back T and roect ry(X) of T and set read TSX) 10 « Timestamp Stamp Ordering Strict Timestamp i a os i esa write_item(X) operation: ack fi Transtc read "TS(X), then delay T ‘until the transaction T” that wrote or read X has terminated (committed a en a on T issues a read_item( operation: \ 2. Transeorr)> he delay T until the transaction T” that wrote or read X ¢ TETS(T) > write_TSC%), Js texminated (committed or aborted). sete te Se) Granularity of data item ‘and multiple granularity locking explaination er. Q9a)Recovery Techniques Based on Immediate U) date ‘Undo/No-redo Algorithm In this algorithm ‘AFIMs of a transaction are flushed to the database disk under WAL before jit commits. 2M mis eason the recovery manager undoes al transactions during recovery. ‘No transaction is redone. sht have completed execution and ready to commit but tis possible that a transaction mig] ‘this transaction is also undone. Recovery Techniques Based on Immediate Update Undo/Redo Algorithm (Single-user environment) Recovery schemes of this category apply undo and also redo for recovery. 34 Ina single-user environment no concurrency control is required but a log is maintained under WAL. ‘Note that at any time there will be one transaction in the commit table or in the active table. The recovery manager performs: Undo i transaction if itis in the active table. Recotery Teh bsigus Based wooo ne in the commit table. Ae isa 3m Undo/Redo Algorithm (Concurrent execution) urrent if Eau { ution Recovery schemes of this category applies undo and also re‘ In concurrent execution envi neo vironment a concurrency control is require Commit table record i Ceti Be ords transaction tobe commited and active table records active transactions. To aii Oe 9 /ery manager checkpointing is used. M_ Undo of a transaction if itis i tion if itis in the active tat i Redo of a transaction ifit ein the commit able in the system and it will be either ,do to recover the database from d and log is maintained under ob) The ARIES Recovery Algorith m The ARIES Recoy, = WAL (Write, AuBotithm is bas Repeating histo, zing) ya 8 will ree ee: aes all actions of : i ea of the datat i Will prevent ARTEO , S from repeat ae repeating th eee The AR) luring rec ; g the completed und eee Te Recovery Algorithm 2 “°°°¥'Y: Which cause, arestarof the recovery proces ARIES recovery algorithm consists of tr ives st identities the dy (¢ active atthe time of crash, The’ Pe determined, ie Redo: neces i 2. Unde: RSS To operations ae pi, is seann : a : crash are undo, led backwards and the Operations of transactions active at the time of ne in reverse order. 3. The Recover m1 s ry Algorithm (contd) 4, jh following steps ae performed £ rare : alysis hase Start at the begin_checkpoint record and proceed to the end_checkpoint ed on: © steps: ated) pages in the buffer and the set of transactions Priate point inthe log where redo isto start is also Redo phase: Starts from the point in the log up to where all dirty pages have been flushed, and move forward to the end of the log. Any change that appears in the dirty page table is redone. 6., Undo phase: Starts from the end of the log and proceeds backward while performing appropriate undo. For each undo it writes a compensating record in the log. ‘The recovery completes at the end of undo phase. Mm 9c)Shadow Paging ae a does not overwrite its BFIM but recorded at another place on the disk. Thus, at e y time a data item has AFIM and BRIM (Shadow copy of the data item) at two diferent amy plaees on the disk ———__ x x” Database ies of data items X and Y: Shadow copies o oes vies of data : : eee "and Y'; Current coples of data Hom en transactions two directories (e m_ To manage access of Are, zy arrangement is illustrated below. Here a page is a data item The dires os Figure 185 Shadow directory e Database dak “aed) ‘An example a shadow paging. Page 2 (old Pages Page 6 Page 2 (new) Page 5 (new) 1m QU0a) Types of Security d ethical issues mm Legal an eS mt Policy issues oe ca i System-related issues Mm The need to identify multiple security levels, Threats to databases Loss of integrity 3M Loss of availability mM Loss of confidentiality To protect databases against these types of threats four kinds of countermeasures can be implemented: Access control ¢ ™ Inference controh Flow control = 3 mM, ™ Encryption ~ 10b) types of discretionary privileges Discretionary access control previledges The typical caring piv discretionary access control in a database system is based on ol the granting and-revoking privileges types of discr privileges ‘The account level At this level, the DBA specifies the parti ivil A , particular privileges that each account h ‘independently of the relations in the database. e ener The relation level (or table level): At this ley j el ile 7 zl AL the aeeouint levy ‘he Privilege to acces each individual relation oF Vi" ities provi itgetfand c2? include ‘ ™ the CREA’ a relation; SCHEMA or crpy the CREATE 'TE TABLE privilege, to create a schema or base the ALTER op EW Privilege, ge to create a relations; | P'Y€8s, to apply seh } ema changes such adding or removing attributes from the DROP priyi privil the MoDIry brivileng delete relations or views; and te SELECT privilege a elt or ‘update tuples; The seen auer to retrieve information from the database by using a vi : ™ This includes b; ies to the relation level br : ase relati Fi Mm The granting and revoking aes and virtual (view) relations. privileges known asthe access ae really follow an authorization model for discreti Mm The rot i eer! pe Fows of a matrix M represents subjects (ses, accounts, programs) columns represent objects (eat p , Mm Each position MG, in the mat (eltions, records, columns, views, operations). that subject i oe ee ix represents the types of privileges (read, write, update; a t pect j. To sentca} the granting and revoking of relation privileges, each relation R in a database is assigned and owner aecount, which s typically the account that was used when the relation was created in the first place. 1M The owner of a relation is given all privileges on that relation. it In SOL2, the DBA can assign and owner to a whole schema by creating the sehen and aasoviating the appropriate authorization identifier with that schema, using the CREATE SCHEMA command. mt The owner account holder can pass privileges on any of the by granting privileges to ‘their accounts. owned relation to other users : 1% Privileges Using Views yes . Specifying GRANT OPTION —>“* « Revoking Privileges : + Propagation of Privileges using the

You might also like