Database Management Systems

Similar documents
SQL Interview Questions

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601

5. Single-row function

Database Management System 9

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions.

Data about data is database Select correct option: True False Partially True None of the Above


B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION. Ch. 1 :- Introduction Database Management System - 1

In-Sem Paper Solution Subject: Database Management System (2015 Patter) August, Answer: [1]

Database Management Systems Paper Solution

UNIT-IV (Relational Database Language, PL/SQL)

Database Technology Introduction. Heiko Paulheim


Sample Question Paper

Oracle Database 11g: SQL and PL/SQL Fundamentals

DATABASE MANAGEMENT SYSTEMS

Introduction to SQL/PLSQL Accelerated Ed 2

Oracle Database: Introduction to SQL/PLSQL Accelerated

Solved MCQ on fundamental of DBMS. Set-1

Sankalchand Patel College of Engineering, Visnagar B.E. Semester III (CE/IT) Database Management System Question Bank / Assignment

Babu Banarasi Das National Institute of Technology and Management

Oracle PL SQL Training & Certification

Essay Question: Explain 4 different means by which constrains are represented in the Conceptual Data Model (CDM).

Sql Server Syllabus. Overview

Unit I. By Prof.Sushila Aghav MIT

Introduction to Computer Science and Business

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

Basant Group of Institution

Mahathma Gandhi University

Chapter 3: The Relational Database Model

PL/SQL Block structure

Oracle Syllabus Course code-r10605 SQL

Oracle Database: SQL and PL/SQL Fundamentals NEW

8) A top-to-bottom relationship among the items in a database is established by a

Relational Database Management System 2014

Oracle Database: SQL and PL/SQL Fundamentals Ed 2

D.K.M COLLEGE FOR WOMEN(AUTONOMOUS),VELLORE DATABASE MANAGEMENT SYSTEM QUESTION BANK

Table of Contents. PDF created with FinePrint pdffactory Pro trial version

DATABASE MANAGEMENT SYSTEM SHORT QUESTIONS. QUESTION 1: What is database?

THE RELATIONAL DATABASE MODEL

Relational Model: History

Database Management System. Fundamental Database Concepts

ROEVER ENGINEERING COLLEGE

Chapter 1: Introduction

Oracle SQL & PL SQL Course

Deccansoft softwareservices-microsoft Silver Learing Partner. SQL Server Syllabus

Relational Database Management Systems Oct/Nov I. Section-A: 5 X 4 =20 Marks

VU Mobile Powered by S NO Group All Rights Reserved S NO Group 2013

Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept]

Introduction to Computer Science and Business

Q.1 Short Questions Marks 1. New fields can be added to the created table by using command. a) ALTER b) SELECT c) CREATE. D. UPDATE.

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model

Chapter 3: Introduction to SQL

Principles of Data Management

Chapter 1 Chapter-1

Sample Copy. Not For Distribution.

Course Logistics & Chapter 1 Introduction

Oracle Developer Track Course Contents. Mr. Sandeep M Shinde. Oracle Application Techno-Functional Consultant

UNIT I. Introduction

UNIT 2 Set Operators

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

20461: Querying Microsoft SQL Server 2014 Databases

CMSC 461 Final Exam Study Guide

Oracle. SQL(Structured Query Language) Introduction of DBMS. Build In Function. Introduction of RDBMS. Grouping the Result of a Query

Relational Database Language

Question Bank PL/SQL Fundamentals-I

Oracle Database: SQL and PL/SQL Fundamentals

M.C.A. (CBCS) Sem.-III Examination November-2013 CCA-3004 : Database Concepts and Tools. Faculty Code: 003 Subject Code:

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13

Database Management System Prof. D. Janakiram Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

CS348: INTRODUCTION TO DATABASE MANAGEMENT (Winter, 2011) FINAL EXAMINATION

SQL STRUCTURED QUERY LANGUAGE

Oracle Database 10g: Introduction to SQL

Exam code: Exam name: Database Fundamentals. Version 16.0

CS2255 DATABASE MANAGEMENT SYSTEMS QUESTION BANK UNIT I

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

Introduction to Databases, Fall 2005 IT University of Copenhagen. Lecture 10: Transaction processing. November 14, Lecturer: Rasmus Pagh

EDUVITZ TECHNOLOGIES

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity

E-R diagrams and database schemas. Functional dependencies. Definition (tuple, attribute, value). A tuple has the form

CS6312 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C

Rajiv GandhiCollegeof Engineering& Technology, Kirumampakkam.Page 1 of 10

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

Name :. Roll No. :... Invigilator s Signature : DATABASE MANAGEMENT SYSTEM

Business Analytics. SQL PL SQL [Oracle 10 g] P r i n c e S e t h i w w w. x l m a c r o. w e b s. c o m

Chapter 3: Introduction to SQL

Database Management

A Unit of SequelGate Innovative Technologies Pvt. Ltd. All Training Sessions are Completely Practical & Real-time

DATABASES SQL INFOTEK SOLUTIONS TEAM

Relational Database design. Slides By: Shree Jaswal

CT13 DATABASE MANAGEMENT SYSTEMS DEC 2015

Query Processing & Optimization

Intro to Transactions

The SQL data-definition language (DDL) allows defining :

U1. Data Base Management System (DBMS) Unit -1. MCA 203, Data Base Management System

Querying Microsoft SQL Server

SYED AMMAL ENGINEERING COLLEGE

Oracle Database 12c: Program with PL/SQL Duration: 5 Days Method: Instructor-Led

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

Transcription:

S.Y. B.Sc. (IT) : Sem. III Database Management Systems Time : 2½ Hrs.] Prelim Question Paper Solution [Marks : 75 Q.1 Attempt the following (any THREE) [15] Q.1 (a) Explain database system and give its applications along with purpose of database [5] systems. (A) Databases are widely used. Here are some representative applications : Enterprise Information Banking and Finance Universities Airlines Telecommunication Purpose of Database Systems : System programmers wrote these application programs to meet the needs of the university. Keeping organizational information in a file-processing system has a number of major disadvantages: Data redundancy and inconsistency : This redundancy leads to higher storage and access cost. In addition, it may lead to data inconsistency; that is, the various copies of the same data may no longer agree. Difficulty in accessing data : The conventional file-processing environments do not allow needed data to be retrieved in a convenient and efficient manner. More responsive data-retrieval systems are required for general use. Data isolation : Because data are scattered in various files, and files may be in different formats, writing new application programs to retrieve the appropriate data is difficult. Integrity problems : The data values stored in the database must satisfy certain types of consistency constraints. Atomicity problems : In many applications, it is crucial that, if a failure occurs, the data be restored to the consistent state that existed prior to the failure. Concurrent-access anomalies : For the sake of overall performance of the system and faster response, many systems allow multiple users to update the data simultaneously. Security problems : Not every user of the database system should be able to access all the data. Q.1 (b) Explain 3 levels of database architecture. [5] (A) A database system is a collection of interrelated data and a set of programs that allow users to access and modify these data. A major purpose of a database system is to provide users with an abstract view of the data. That is, the system hides certain details of how the data are stored and maintained. Data Abstraction : Developers hide the complexity from users through several levels of abstraction, to simplify users interactions with the system: Physical level : The lowest level of abstraction describes how the data are actually stored. The physical level describes complex low-level data structures in detail. Logical level : The next-higher level of abstraction describes what data are stored in the database, and what relationships exist among those data. The logical level thus describes the entire database in terms of a small number of relatively simple structures. 1

This is referred to as physical data independence. Database administrators, who must decide what information to keep in the database, use the logical level of abstraction. View level : The highest level of abstraction describes only part of the entire database. The view level of abstraction exists to simplify their interaction with the system. The system may provide many views for the same database. Q.1 (c) Explain types of attributes with examples. [5] (A) Simple and composite attributes : Composite attributes, on the other hand, can be divided into subparts (that is, other attributes). For example, an attribute name could be structured as a composite attribute consisting of first name, middle initial, and last name. Example Simple attribute eid Composite attribute ename, FN, MN, LN Single-valued and multivalued attributes: The attributes in our examples all have a single value for a particular entity. For instance, the student ID attribute for a specific student entity refers to only one student ID. Such attributes are said to be single valued. There may be instances where an attribute has a set of values for a specific entity. Suppose we add to the instructor entity set phone number attribute. This type of attribute is said to be multivalued. Example Single valued attribute eid Multivalued attribute Phno. Derived attribute: The value for this type of attribute can be derived from the values of other related attributes or entities. As another example, suppose that the instructor entity set has an attribute age that indicates the instructor s age. If the instructor entity set also has an attribute date of birth, we can calculate age from date of birth and the current date. Thus, age is a derived attribute. Q.1 (d) List and explain 12 codd s Rules. [5] (A) 1. Information : All information in a relational database must be logically represented as column values in rows within tables. 2. Guaranteed access : Every value in a table is guaranteed to be accessible through a combination of table name, primary key value, and column name. 3. Systematic treatment of nulls : Nulls must be represented and treated in a systematic way, independent of data type. 2

4. Dynamic online catalog based on the relational model : The metadata must be stored and managed as ordinary data that is, in tables within the database. Such data must be available to authorized users using the standard database relational language. 5. Comprehensive data sublanguage : The relational database may support many languages; however, it must support one well-defined, declarative language as well as data definition, view definition, data manipulation (interactive and by program), integrity constraints, authorization, and transaction management (begin, commit, and rollback). 6. View updating : Any view that is theoretically updatable must be updatable through the system. 7. High-level insert, update, and delete : The database must support set-level inserts, updates, and deletes. 8. Physical data independence : Application programs and ad hoc facilities are logically unaffected when physical access methods or storage structures are changed. 9. Logical data independence : Application programs and ad hoc facilities are logically unaffected when changes are made to the table structures that preserve the original table values (changing order of columns or inserting columns). 10. Integrity independence : All relational integrity constraints must be definable in the relational language and stored in the system catalog, not at the application level. 11. Distribution independence : The end users and application programs are unaware of and unaffected by the data location (distributed vs. local databases). 12. Nonsubversion : If the system supports low-level access to the data, users must not be allowed to bypass the integrity rules of the database. 13. Rule zero : All preceding rules are based on the notion that to be considered relational, a database must use its relational facilities exclusively for management. Q.1 (e) Draw an ER diagram for Hospital Management System. [5] (A) Q.2 Attempt the following (any THREE) [15] Q.2 (a) Explain different types of keys with examples. [5] (A) Types of Keys : (a) Superkey : An attribute or combination of attributes that uniquely identifies each row in a table. 3

(b) Candidate key : A minimal (irreducible) superkey; a superkey that does not contain a subset of attributes that is itself a superkey (c) Primary key : A candidate key selected to uniquely identify all other attribute values in any given row; cannot contain null entries. (d) Foreign key : An attribute or combination of attributes in one table whose values must either match the primary key in another table or be null. (e) Secondary key : An attribute or combination of attributes used strictly for data retrieval purposes. Q.2 (b) Explain features of good relational database design. [5] (A) 1. Design Alternative: Larger Schemas : This suggests that using inst dept is a bad idea since it stores the budget amounts redundantly and runs the risk that some user might update the budget amount in one tuple but not all, and thus create inconsistency. 2. Design Alternative: Smaller Schemas : (a) Consider an extreme case where all we had were schemas consisting of one attribute. No interesting relationships of any kind could be expressed. (b) The flaw in this decomposition arises from the possibility that the enterprise has two employees with the same name. Fig. : Loss of information via a bad decomposition. (c) The two original tuples appear in the result along with two new tuples that incorrectly mix data values pertaining to the two employees named Kim. Although we have more tuples, we actually have less information in the following sense. We can indicate that a certain street, city, and salary pertain to someone named Kim, but we are unable to distinguish which of the Kims. Thus, our decomposition is unable to represent certain important facts about the university employees. Clearly, we would like to avoid such decompositions. We shall refer to such decompositions as being lossy decompositions, and, conversely, to those that are not as lossless decompositions. 4

Q.2 (c) Explain 1NF, 2NF with examples. [5] (A) First normal form (1NF) As per the rule of first normal form, an attribute (column) of a table cannot hold multiple values. It should hold only atomic values. Example : Suppose a company wants to store the names and contact details of its employees. It creates a table that looks like this : emp_id emp_name emp_address emp_mobile 101 Herschel New Delhi 8912312390 102 Jon Kanpur 8812121212 9900012222 103 Ron Chennai 7778881212 104 Lester Bangalore 9990000123 8123450987 Second normal form (2NF) A table is said to be in 2NF if both the following conditions hold: Table is in 1NF (First normal form) No non-prime attribute is dependent on the proper subset of any candidate key of table. An attribute that is not part of any candidate key is known as non-prime attribute. Example: teacher_id subject teacher-age 111 Maths 38 111 Physics 38 222 Biology 38 333 Physics 40 333 Chemistry 40 Candidate Keys: {teacher_id, subject} Non prime attribute: teacher_age The table is in 1 NF because each attribute has atomic values. However, it is not in 2NF because non prime attribute teacher_age is dependent on teacher_id alone which is a proper subset of candidate key. This violates the rule for 2NF as the rule says no nonprime attribute is dependent on the proper subset of any candidate key of the table. To make the table complies with 2NF we can break it in two tables like this: teacher_details table : teacher_id teacher_age 111 38 222 38 333 40 Teacher_subject table : teacher_id teacher_age 111 Maths 111 Physics 222 Biology 333 Physics 333 Chemistry Now the tables comply with Second normal form (2NF). 5

Q.2 (d) Define Relational algebra? Explain selection & projection operation. [5] (A) 1. The relational algebra is a procedural query language. It consists of a set of operations that take one or two relations as input and produce a new relation as their result. The fundamental operations in the relational algebra are select, project, union, set difference, Cartesian product, and rename. In addition to the fundamental operations, there are several other operations namely, set intersection, natural join, and assignment. 2. The Select Operation : The select operation selects tuples that satisfy a given predicate. We use the lowercase Greek letter sigma to denote selection. Thus, to select those tuples of the instructor relation where the instructor is in the Physics department, we write: dept_name = Physiscs (instructor) 3. The Project Operation : Suppose we want to list all instructors ID, name, and salary, but do not care about the dept name. The project operation allows us to produce this relation. The project operation is a unary operation that returns its argument relation, with certain attributes left out. Since a relation is a set, any duplicate rows are eliminated. Projection is denoted by the uppercase Greek letter pi. ID, name, salary (instructor) Q.2 (e) Explain different types of joins with example. [5] (A) SQL joins combine records coming from more than one table using the common values (columns) between those tables. Join is denoted as Different types of joins (i) inner joins (ii) Equijoins (a) Equijoin with using construct (b) Natural join (iii) Cross join (iv) Outer Join Full-outer join Right outer join Left outer join (i) Inner joins : It is similar to basic join operator. Example : SELECT * FROM FACAULTY INNER JOIN DEPT. ON FACULTY.DEPT_ID = Dept.Dept_ID (ii) Equijoins : Equijoin performs a join against equality or matching column (s) values of the associated tables. An equal sign (=) is used as comparison operator in the where clause to refer quality. Select * From table 1 Join table 2 [On (join_condition) (a) Equijoin with the USING construct : applicable with columns having same name. SELECT * FROM FACULTY INNER JOIN Dept. USING (Dept_SD); 6

(b) Natural Join : Natural join is a type of Equijoin and is structured in such a way that, columns with same name of associate tables will appear once only. It was created to get rid of the second attribute in an Equijoin condition. Denoted by * SYNTAX : Select * From table 1 * or Natural Join table 2; (iii) Cross Join : Cross Join produces a result set which is the number of rows in the first table multiplied by number of row in the second table, if no WHERE clause is used along with CROSS JOIN. This kind of result is called as Cartesian Product. If WHERE clause is used with CROSS JOIN, it functions like INNER JOIN. Select * From table 1 Cross new table 2 (iv) Outer Join : (i) In NATURAL JOIN row tuples without a matching (or related) tuple are eliminated from the join result. Tuples with null in the join attributes are also eliminated. This amounts to loss of information. (ii) A set of operations, called outer joins, can be used when we want to keep all the tuples in R, or all those in S, or all those in both relations in the result of the join, regardless of whether or not they have matching tuples in the other relation. (iii) The left outer join operation keeps energy tuple in the first relation R in R S; if no matching tuple is found in S, then the attributes of S on the join result are filled or padded with null values. (iv) A similar operation, right outer join, keeps energy tuple in the second or right relations in result. A third operation, full outer join keeps all tuples in both the left & right relation when no matching tuples are found padding them with null values as needed. SYNTAX OF LEFT OUTER JOIN Select * From table 1 Left outer join table 2 On table 1.column_name = table 2, column_name; RIGHT OUTER JOIN : Select * From table 1 Right outer join table 2 On table 1.column_name = table 2, column_name; Full-outer join : Select * From table 1 Full Outer join table 2 ON Table 1.column_name = table 2.column_name; 7

Q.3 Attempt the following (any THREE) [15] Q.3 (a) Explain different types of constraints. [5] (A) There are different types of constraints: a. Domain Integrity Constraints: The domain constraints are considered as the most basic form of integrity constraints. Domain is a set of permitted values for an attribute. Constraints: o Not Null By setting the NOT NULL constraint we can assure that a column does not hold a NULL value. o Unique UNIQUE Constraint as the name suggests, can take only unique values in a column or set of columns. It keeps uniqueness of the table. o Default When a user does not provide a value to the column while inserting the records in the table, the DEFAULT constraint provides a default value to that column. b. Entity Integrity Constraints: Primary Key Constraint o Under Entity Integrity Constraint Primary key is the main factor. o Primary key uniquely identifies each record in a table. It must have unique values and cannot hold null values i.e. Primary key is the combination of NOT NULL & UNIQUE constraints. c. Referential Integrity Constraint: Foreign Key o The Foreign key constraint is also known as Referential Integrity Constraint. In this constraint one field is common in between two tables. o Foreign key represent relationships between tables. There is parent child relationship between two tables having common column. o The master table can be referenced as parent while the transaction table is considered as child. The common field will work as primary key in parent table while foreign key in child table. Q.3 (b) Write short note on DDL, DML & DCL. [5] (A) 1. Data Definition Language (DDL) The DDL is also used to specify the structure of each table, set of associated values with each attribute, integrity constraints, security and authorization information for all the tables and physical storage structure of all the tables on the disk. Let s take SQL for instance to categorize the statements that comes under DDL. o To create the database instance CREATE o To alter the structure of database ALTER o To drop database instances DROP o To rename database instances RENAME 2. Data Manipulation Language (DML) The Data Manipulation Language (DML) is used for accessing and manipulating data in a database. DML provides a set of functionalities to support the basic data manipulation operations on the data stored in the database. It allows users to access, insert, update, and delete data from the database. o To access or read records from table SELECT o To insert record into the table INSERT o Update the records in table UPDATE o Delete the records from the table DELETE 8

3. Data Control Language (DCL) Data Control Language (DCL) is used to control the user access to the database related elements like tables, views, functions, procedures and packages. It provides different levels of access to the objects in the database. o To grant access to user GRANT o To revoke access from user REVOKE Grant : GRANT is used to provide the privileges to the users on the database objects. Revoke: REVOKE removes the privileges given on the database objects. 4. Transaction Control Language (TCL) TCL statements allow you to control and manage transactions to maintain the integrity of data within SQL statements. o BEGIN Transaction opens a transaction o COMMIT Transaction commits (Save permanently) transactions o ROLLBACK Transaction ROLLBACK (Cancels, undo) transactions in case of any Q.3 (c) Explain view objects in SQL with example. [5] (A) 1. Security in View A view is a virtual table containing the records of one or more tables based on SQL statement executed. Just like a real table, view contains rows and columns. You can add SQL functions, WHERE clause, and JOIN statements to a view and present the data as if the data were coming from one single table. The changes made in a table gets automatically reflected in original table and vice versa. 2. Data Independence in View A view may be thought of as a virtual table, that is, a table that does not really exist in its own right but 4 instead is derived from one or more underlying base tables. in other words, there is no stored file that directly represents the view instead a definition of view is stored in data dictionary. 3. Creating View a. Creating view having specific fields but all the records from existing table c. Creating new view having specific records but all the fields from existing table 4. Updating View a. Update query is used to update the records of view. Updation in view reflects the original table also. Means the same changes will be made in the original table also. Syntax 9

b. Restrictions on Modification of Views In case of view containing joins between multiple tables, only insertion and updation in the view is allowed, deletion is not allowed Data modification is not allowed in the view which is based on union queries. Data modification is not allowed in the view where GROUP BY or DISTINCT statements are used. In view the text and image columns can t be modified. 5. Dropping View DROP query is used to delete a view. Q.3 (d) Explain aggregate functions with examples. [5] (A) MIN returns the smallest value in a given column MAX returns the smallest value in a given column SUM returns the sum of the numeric values in a given column AVG returns the average value of a given column COUNT returns the total number of values in a given column COUNT (*) Returns the number of rows in a table Aggregate functions are used to compute against a "returned column of numeric data" from your SELECT statement. Example SELECT AVG(salary) FROM employee; SELECT Count(*) FROM employee; Q.3 (e) Write SQL Queries for the given database Employee (eid, ename, street, city) Works (eid, cid, salary) Company (cid, cname, city) (A) (i) Modify the database so that Jack now lives in Mumbai. (ii) Give all employees of ANZ corporation a 10% raise in salary. (iii) Find all employee id who live in same cities as the company for which they work. (iv) Give total number of employees. (v) Find the highest paid employee. [5] (1) Update employee SET city = Mumbai where ename = Jack (2) Update works SET salary = Salary * 1.1 where (id) IN (select cid from Company where / name = ANZ Corporation ); (3) Select distinct eid, ename From employee, works, company where employee.eid = works.cid 10

AND works.cid = Company.cid AND employee.city, Company.City; (4) Select Count (*) As total employees from Employee; (5) Select eid from works where salary = (select max / salary) from works) Q.4 Attempt the following (any THREE) [15] Q.4 (a) Describe ACID property for a transaction. [5] (A) 1. Atomicity Atomicity is based on the concept that each transaction be all or nothing : if any one part of the transaction in a sequence fails, then the entire transaction fails, and there will be no change in database state. This property states that, either all operations contained by a transaction are done successfully or none of them complete at all. To maintain the consistency of data this property is very useful. 2. Consistency The consistency property ensures that the transaction executed on the database system will bring the database from original consistent state to another. 3. Isolation The isolation property ensures that the system state should be same that would be obtained if transactions were executed sequentially, i.e., one after the other. The effect of any incomplete transaction should not be visible to other transaction. This can be achieved isolation. 4. Durability The durability property ensures that after transaction is committed successfully the updates made should remain permanent in the database even in the event of power loss, crashes or errors. Q.4 (b) List & explain different states through which transaction goes during its [5] execution. (A) 1. There are five states of transaction. During execution, transaction will be in one of the following state. 2. Active This is the first state of transaction. In this state the transaction is being executed. This state is entry point to every transaction. Transactions which are in active state indicate that their execution has been started. 3. Partially Committed When a transaction completes all operations, it will enter into partially committed state. Even when the last operation has been performed; data is still not saved to the database. 4. Failed If execution of transaction cannot proceed due to failure of the system or failure in database, then the transaction is said to be in failed state. 5. Abort In case of a failed transaction, the modification done in database during transaction processing must be rolled back to ensure the atomicity and consistency of database. The transaction enters into Abort state. The transaction is thus in abort state after roll back operation is performed. It is the end of transaction when any fault occurs. 11

6. Committed If without any error a transaction gets completed successfully it will come into committed state which will allow to made changes permanent into database. This is the last step of a transaction, if it executes without any failure. Either transaction may goes through active -partially committed - committed or through active - Failed - aborted, or through active - partially committed - failed - abort. Q.4 (c) Explain concept of schedule & its types. [5] (A) 1. Schedule: a. A schedule is a collection of several transactions that can be executed in a predefined order as a single unit, b. Schedule may combine the operations of one transaction with other transaction. These operations must be in same sequence as they occur in their individual transactions. c. Depending on the arrangement of these transactions, schedule can be divided into two types: Serial Schedule and Concurrent Schedule. 2. Types of Schedule a. Serial Schedule In serial schedule all the transactions in the schedule are executed one after another. Operations of different transactions are not interspersed with each other. For example, account M has Rs. 500 and account N has Rs. 1000 initially. Transaction T1 transfers Rs. 200 from account M to N and Transaction T2 transfers Rs. 100 from account M to N. T1 and T2 can be scheduled in two ways for execution: I. Schedule 1 : Serial schedule for T1 followed by T2 b. Concurrent Schedule: Concurrent schedule is a schedule where, several transactions are executed simultaneously. The operations of one transaction can be mixed with operations of other transaction. Schedule 3 Concurrent schedule for T1 and T2 12

After execution of both transactions M holds Rs. 200 and N holds. Rs. 1300 In this example concurrent schedule also provides same result as the above two serial schedules provide. But not all the concurrent schedules provide result in consistent state. Q.4 (d) Explain lock-based protocol. [5] (A) 1. Two-Phase Locking (2PL) a) In this scheme, each transaction makes lock and unlock request in 2 phases: A Growing Phase (or An Expanding Phase or First Phase) : In this phase, new locks on the desired data item can be acquired but none can be released. A Shrinking Phase (or Second Phase) : In this phase, existing locks can be released but no new locks can be acquired. b) In the beginning, the transaction is in growing phase in which it acquire lock as per requirement. After completing the work, the transaction releases the locks and enters into shrinking phase. The transaction cannot request for new locks after_releasing the locks. c) The point in the schedule where the transaction acquires its final lock is called as lock point. d) In Serializability the main issue is regarding write operation. The parallel write operations may create inconsistency in the database. The parallel read operations do not create any problem. e) In serial schedule, as the transactions are executed one after other, there is no risk of parallel write operations which may lead to inconsistency. 2. Strict Two-Phase Locking In Strict two phase locking protocol the first step of acquiring all the locks is same as first phase of two phase locking protocol. But the difference in Strict two phase locking and two phase locking is that Strict two phase locking protocol does not release the lock after using it. It holds all the locks till it does not reach to commit point. Q.4 (e) Explain deadlock detection. [5] (A) 1. Detecting deadlock situation in advance is always good instead of aborting a transaction. A deadlock avoidance mechanism is used to detect deadlock situation in advance. An algorithm that examines the state of the system is called periodically to check the occurance of deadlock. In deadlock avoidance wait-for graph method is used. 2. Wait-for Graph: Wait-for-graph scheme uses a graph (set of edges and vertices (nodes)) to detect deadlock in the system. A node is created when a transaction enters into system. When a transaction T, requests for a lock on resource X which is held by some other transaction T1, a directed edge is created from T to T1. 13

This edge is removed when T releases resource X, and T1 locks that resource. Waitfor graph indicates which transaction is waiting for another transaction to complete. A graph with cycle indicates the occurrence of deadlock in the system. The wait for graph has following situation o Transaction Ti is waiting for transaction T2 and T3 o Transaction T3 is waiting for transaction T2 o Transaction T2 is waiting for transaction T4 Here the graph has no cycle; hence it is not in deadlock state. Consider the transaction T4 is requesting an item held by T3 then a directed edge from T4 to T3 will be drawn. Now the graph has a cycle T2- T4- T3-*T2 Here the transactions T2, T3 AND T4 are in deadlock state. Q.5 Attempt the following (any THREE) [15] Q.5 (a) What is PL/SQL and explain the advantages of PL/SQL. [5] (A) 1. PL/SQL : It offers a procedural extension that allows for modularity, variable declaration, loops and other logic constructs, and advanced exception handling. PL/SQL is a combination of SQL along with the procedural features of programming languages. It is a database-oriented programming language that is a powerful extension of SQL with procedural capabilities. The key strength of PL/SQL is its tight integration with the Oracle database. 2. PL/SQL Engine : PL/SQL engine is a tool used to define, compile, and run PL/SQL program units. 14

Advantages of PL/SQL : 1. Block Structure: PL/ SQL consist of blocks of code, which can be nested within each other. Each block forms a unit or a logical module and is stored in the database so that it can be reused. 2. Tight Integration with SQL: PL/SQL is tightly integrated with SQL, which is popular and most widely used database manipulation language. 3. Procedural Language Capability : PL/SQL includes procedural language constructs such as conditional statements and looping constructs. 4. High Performance : PL/SQL allows sending the entire block of statements to the database, thereby reducing traffic between the application and the database. 5. High Productivity : PLISQL allows writing compact code for manipulating data. PL/SQL can query, change, and automatically update data in a database. 6. Portability : PL/SQL applications can run on any operating system and platform where Oracle Database is running. 7. Scalability : Stored subprograms of PL/SQL increase scalability by centralizing application processing on the database server. 8. Manageability : PL/SQL stored subprograms have only one copy maintained on the database server which can be changed without having to affect the applications invoking them, thereby increasing the maintainability. 9. Support for Object-Oriented Programming : PL/SQL supports object-oriented programming and the use of Abstract Data Types (ADTs). 10. Support for Developing Web Applications : PL/SQL allows creating applications that generate web pages that directly access the database. 11. Support for Developing Server Pages : PL/SQL Server Pages (PSPs) allows developing web pages with dynamic content. 12. Error Handling : PL/SQL handles exceptions effectively during the execution of a PL/SQL program. Q.5 (b) State & explain the various data types of PL/SQL. [5] (A) 1. Every PL/SQL variable, constant or a parameter has a data type which determines its storage structure, the values that can be assigned to it and operations that can be performed on it. 2. Scalar Data Type (a) Numeric Data Type (b) Character Data Type (c) Boolean Data Type (d) DateTime Data Type : 3. %Type Attribute : A special attribute known as %TYPE allows us to declare a data item of the same data type as previously declared variable or column of the table without having to remember it. The item declared with %TYPE is called the referencing item, and the previously declared item is called the referenced item. 4. Handling Variables in PL/SQL : Variables must be declared before they are used. The PL/SQL variables can be a scalar type such as DATE, NUMBER, VARCHAR2, BOOLEAN, LONG and CHAR, or a composite type, such as VARRAY. Only TRUE, FALSE or NULL can be assigned to BOOLEAN type of variables. Q.5 (c) Explain the various forms of IF statements used in PL/SQL. [5] (A) 1. IF Statements : An IF statement executes a sequence of statements, depending on the value of a condition. When the condition is satisfied, the necessary option will be executed. There are three forms of IF statements: IF-THEN, IF-THEN-ELSE, and IF-THEN-ELSIF. 15

2. IF-THEN Statement : The simplest form of IF statement associates a condition with a sequence statements enclosed by the keywords THEN and END IF (not ENDIF). IF- Then executes the statement or a block of statements if the condition returns true. 3. IF-THEN-ELSE Statement : In this type of IF statement there is a keyword ELSE followed by an alternative sequence of statements which can execute when the condition with if evaluates to false. 4. NESTED IF-THEN- ELSE statements : IF statements can also be nested inside other IF statements. This allows us to check more than one condition in a series and execute the appropriate block of statements depending on the conditions. Q.5 (d) Define cursors and give its types. [5] (A) 1. Cursor is a pointer to the private area in SQL that stores information about processing a specific DML statement. The drawback with select statement is that it returns only one row at a time in a PL/SQL block. 16

2. Cursors can be classified as : Implicit Cursor These cursors are also called as internal cursors and are managed by Oracle itself Explicit Cursor These are User-defined Cursor used for external Processing Implicit Cursor : 1. Implicit cursor is a session cursor which is opened every time you run a SELECT or DML statement in the PL/SQL block. An implicit cursor closes after its associated statement run but its attributes values remain available until another SELECT or DML statement is executed. Cursor attributes return information about the state of the cursor. The syntax for an implicit cursor attribute is SQLattribute(e.g. SQL%FOUND). SQLauribute will always refer to the recently run DML or SELECT INTO statement. 2. Implicit cursor attributes are : SQL%ISOPEN SQL % FOUND SQL%NOTFOUND SQL % ROWCOUNT 3. Drawbacks of Implicit Cursors : The implicit cursor has the following drawbacks: Implicit cursors are less efficient than an explicit cursor. Implicit cursors are more vulnerable to data errors. Implicit cursors provide less flexibility to implement programming control. Explicit Cursor : The Cursor which is declared by user is called as Explicit Cursor. Following are the steps of using an explicit Cursor: DECLARE Cursor in the declaration section. OPEN the cursor in the Execution Section. FETCH the data from cursor into PL/SQL variables or records in the Execution Section. CLOSE the cursor in the Execution Section before we end the PL/SQL Block. Example : Q.5 (e) Define and Explain Triggers. [5] (A) 1. A trigger is a PL/SQL block structure or stored procedure that defines an action the database should take when some data base related event occurs. It plays automatically depending on the particular condition. A trigger is fired or executed when a DML statements like Insert, Delete, Update is executed on a database table. A trigger is 17

triggered automatically at predefined timing and event, when an associated DML statement is executed. Triggers are useful in achieving security and auditing. It also maintains referential integrity and data integrity. 2. Advantages of using Triggers : To check the integrity of data. To catch errors in business logic. SQL triggers run the scheduled tasks SQL triggers are very useful to audit the changes of data in tables. 3. Disadvantages of using SQL Triggers : SQL triggers only can provide an extended validation and they cannot replace all the validations. SQL triggers may increase the overhead of the database server. 4. Types of Triggers : (a) BEFORE Triggers : BEFORE triggers are also used to derive specific column values before completing a triggering INSERT or UPDATE statement. (b) AFTER Triggers : The Oracle-defined AFTER ROW trigger, We can create as many triggers of the preceding different types as we need for each type of DML statement (INSERT,UPDATE, or DELETE). 5. Creating Triggers : Database trigger consist of four parts: (a) The trigger type (b) The triggering event (c) Trigger condition (d) Trigger body 18