Download MAYUR Relational Database Management System Model Answer

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Open Database Connectivity wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

SQL wikipedia , lookup

PL/SQL wikipedia , lookup

Serializability wikipedia , lookup

Database wikipedia , lookup

Relational algebra wikipedia , lookup

Ingres (database) wikipedia , lookup

Concurrency control wikipedia , lookup

Clusterpoint wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
Relational Database Management System
Model Answer Paper
Subject code:-12065
3 Hours / 100 Marks
1. Attempt any TEN of the following:
a) List the advantages of file processing system over DBMS.
Ans:-The disadvantages of file processing system are as follows:1) Data redundancy and inconsistency.
2) Difficult in accessing data.
3) Data isolation.
4) Data integrity.
5) Concurrent access is not possible.
6) Security problems.
b) Define data independence and list its types.
Ans:-Data Independence means the property to change one schema without affecting other
schema.
The types of data independence are:
1) Physical Data Independence.
2) Logical Data Independence.
c) List the application of database management system.
Ans:-The application of database management system are as follows:1) Banking.
2) Airline Reservation.
3) Credit Card Transaction.
4) Telecommunication.
5) Finance.
6) Sales.
d) Explain the term database schema and instances.
Ans:-Schema is the overall structure of the database that defines the object in the database.
Schemas are generally stored in a data dictionary. The schema defines a table, the fields,
relationships, views, indexes & other elements. Database system supports three database
schemas:1) Physical schema.
2) Logical schema.
3) Sub- schema.
Database changes over time as information is deleted or inserted. The collection of information
stored in the database at a particular is called as instance of the database.
1
e) What are views? give example.
Ans:-A view in SQL query output which is permanently stored in the database and assign a name.
The result of the stored query are visible through the view and SQL. Lets you access these query
results as if there were in fact a real table in the database.
e.g.:- A view can be created as follows:
create view emp_view
as
select * from emp where salary between 10000 and 20000;
the output of the select query will be stored in the database with name emp_view.
f) Describe the command to change the data in the table with example.
Ans:-The command used to change data in the table is update.
With this command we can update zero or more rows in the table.
The syntax of update table is as follows:
Update<Table_name>SET<Attribute_name>=<Value> where <search condition>;
e.g.:update dept SET dept_name=’sales’ where dept_no=100;
g) Draw the block structure of PL/SQL.
Ans:-A PL/SQL has following block structure:
Declare
/* Declare Section */
Begin
/* Executable Statements */
Exception
/* Exception Handling Section */
End;
h) What is multivalued dependencies.
Ans:-Multivalued dependency is a dependency where one attribute value is potentially a
“Multivalued Fact” about another and the attribute must be independent of each other’s.
If there are three attributes involved in a relation A, B & C. Then for every value A will have
respective value for B and C. But it is necessary that both B and C values are independent of
others. Multivalued dependency is represented by:
A
B
A
C
Example:
Course
teacher
Course
book
i) What is the purpose of normalization?
Ans:-Normalization normally involves dividing large, badly formed tables into smaller, wellformed tables and defining relationships between them.
Purpose of Normalization:
1) To eliminate redundancy.
2) To organize data efficiently.
3) To reduce the potential for data anomaly.
4) Speed up the database access.
2
j) Draw the state diagram of transaction?
Ans:-State diagram of Transaction
Partially
committed
committed
Active
Failed
rollback
Aborted
k) What is meant by a schedule?
Ans:-The chronological ordering of transaction is called as Schedule. It can consist of set of
transactions that are executing serially or concurrently.
e.g.:- Consider five transaction T1, T2, T3, T4&T5.
Order 1: T1 T2 T3 T4 T5
Order 2: T2 T3 T4 T5 T1
Order 3: T3 T4 T5 T1 T2
Order 4: T4 T5 T1 T2 T3
Order 5: T5 T1 T2 T3 T4 & so on.
There are two types of schedules:
1) Serial schedule
2) Concurrent schedule
l) What is deadlock recovery?
Ans:-When deadlock is detected some transaction will have to rolled back to break the deadlock.
This is the most common solution to recover from deadlock. The following steps should be
considered for roll backing the transactions
1) Selecting the transaction to be rolled back.
2) How much long the transaction to rollback.
3) Starvation.
3
2. Attempt any FOUR of the following:
a) How to grant and revoke privileges to users.
Ans:1) Grant command issued to give privileges or authorities to the users. The authorities can be
insert, delete, update and select on specific database object.
SYNTAX:
Grant <privileges>on<relation>to<users>;
E.g.:
Grant delete, update on employee to U1, U2, U3;
2) Revoke command is used to withdraw privileges which are previously assigned to the users.
SYNTAX:
Revoke<privileges>on<relation>from<users>;
E.g.:
Revoke delete, update on employee from U1, U2, U3;
b) What are the requirement of data security?
Ans:-Security in a database involves both policies and mechanism to protect data and ensure that
it is not accessed, altered or deleted without proper authorization.
To protect database we must take security measures at various levels as follows:
1) Physical Consideration:-The physical location where the actual computer system is located
should be secured.
2) Human consideration:-Users of database system should be authorized carefully.
3) Operating System:-The operating systems need to be hardened for added security.
4) Network Level:-Security within the network is essential since database allows remote access
to data through networks.
5) Database System:-The database system should be responsible for violation of unauthorized
access.
c) Compare relational model and hierarchical model.
Ans:Sr.no
Hierarchical Model
Relational model
1.
2.
3.
4.
Hierarchical Model is based on
tree like structure.
This model follows one to many
relation.
The main application is in
mainframe database systems.
This model is less popular.
This is table based model i.e.
collection of rows and columns.
This model follows many to
many relationship.
The application are unlimited.
This model is more popular.
d) Draw overall structure of DBMS.
Ans:e) What is DBMS? Explain the characteristics of DBMS.
Ans:-DBMS stands for Database Management System. It is collection of interrelated data and
programs which are used to access those data.
The characteristics of DBMS are as follows:
1) Represents complex relationship between data.
4
2) Control data redundancy.
3) Enforces user defined rules.
4) Ensures data sharing.
5) It has automatic and intelligent backup and recovery procedures.
6) It has central dictionary to store information.
7) Pertaining to data and its manipulation.
8) It has different interfaces via which users can manipulate the data.
9) Enforced data access authorization.
f) Explain in brief client server architecture with example.
Ans:1) A network architecture in which each computer process on the network is either a client or a
server.
2) Servers are powerful computers or processes dedicated to managing disk drivers, printers, or
network traffic.
3) Clients are PCs or workstations on which users run application. Clients rely on servers for
resource such as files, devices, and even processing power.
4) In the client/server architecture clients required services and server provides those services.
5) A variety of servers exist in today’s internet—web servers, mail servers, FTP servers, and so
on.
6) The client/server architecture is an example of a centralized architecture where the whole
network depends on central points namely servers to provide services.
SERVER
Client
Client
Client
Client
5
3. Attempt any FOUR of the following:
a) Explain on delete cascade clause with the help of example.
Ans:-On Delete Cascade: It indicates that when the row in the parent table is deleted the
dependent rows in the child table will also be deleted. It can be used with referential integrity
constraint.
e.g.:
create table emp(eno number(6) primary key, ename varchar(25), Dno number(5) references
dept(Dno) on delete cascade.
In above example the entries of Dno from dept table is deleted.
b) List and explain the types of attributes in details.
Ans:-The attributes can be classifies into the following types:1) Simple and composite attributes.
2) Single valued and multi valued attributes.
3) Stored and derived attributes.
4) Complex attributes.
Simple attribute:-Attribute that consist of a single atomic value.
Example:-salary, age, etc.
Composite attribute:-Attribute values not atomic.
Example:-Address: ’House_no: city: state’
Name: ‘first name: middle name: last name’
Single valued attribute:-Attributes that holds a single value.
Example1:-Age
Example2:-City
Example3:-customer id.
Multi valued attributes:-Attributes that holds multiple values.
Example:-A person may have several college degrees.
Stored attribute:-An attribute that supplies a value to the related attribute.
Example:-Date of birth
Derived attribute:-An attribute that’s value is derived from a stored attribute.
Example:-Age, and it’s value is derived from the stored attribute date of birth.
Complex attribute:-A complex attribute that is both composite and multi valued.
6
c) Draw ER diagram for library management system. The library should maintain the data
about staff, student and books.
Ans:d) Define the term primary key and candidate key.
Ans:1) Primary key
Within a given relation there is always one attribute which has values that are unique in a
relation and thus can be used to uniquely identify tuples of the relation such a unique
tuple identifier is called as Primary Key.
2) Candidate key
The super key for which no proper subset is a super key, such minimal super keys are
called as candidate key.
e) Consider the structure as student(stud_id, stud_name, stud_addr, stud_city, stud_per) write
algebra expression for following:
 Find the names of students those who scored first class.
 Find the stud_id, stud_addr, from the student database.
Ans:1) ∏stud_name(Ϭstud_per>=60(student))
2) ∏ stud_name,stud_add(student)
f) Describe the following commands:
 Create table.
 Rename table.
Ans:1) Create table:-The create table command is used to create table definition.
SYNTAX:Create table<table_name>(column1 datatype(size), column2 datatype(size),……., column n
datatype(size));
EXAMPLE:Create table emp(eno number(5) primary key, ename varchar2(30), Dno number(6));
2) Rename:-The rename command is used to rename the existing tables. Only the owner of the
table can rename the table.
SYNTAX:Rename<table_name> To <new table name>;
EXAMPLE:Rename books to book_details;
7
4. Attempt any FOUR of the following:
a) Explain domain integrity constraint with suitable example.
Ans:Domain Integrity Constraint:-It checks whether value entered in the row is from the given range
of values or not.
There are two types of domain integrity constraint: Not Null
 Check
a. Not Null Constraint:It is used to avoid the absence of value in a row for a particular column. Not null
constraint can be specified at the time of table creation or after the table creation with
alter table command.
Syntax:I.
At the time of table creation
Create table table_name(column_name1 datatype (size) not null, column_name n datatype (size));
Example:Create table emp(emp_idnumber(5) not null,emp_namevarchar(10));
b. Check Constraints:It is used to avoid unnecessary values to the columns. This constraints defines the
condition that each row must satisfy.
Syntax:1) At the time of table creation
Create table table_name(column_name1 datatype (size)constraintconstrain_name
check(condition));
Example:Create table bill (bill_nonumber(10),bill_amount number(5,2) constraint ABCD
check(bill_amount!=0.00));
b) What is cursor? Explain any two types of cursors.
Ans:-The identifier of the memory area where command is processed and executed is called as
cursor.
There are two types of cursors:1) Implicit cursor:-When PL/SQL uses select command and result is single row, it creates
implicit cursor. PL/SQL internally manages implicit cursors.
2) Explicit cursors:-When PL/SQL uses select command and result is more than single row, it
creates explicit cursor. The result set of rows are obtained by Explicit cursors.
There are mainly four command which handles explicit cursors:1) Declare: It defines the cursor.
8
2) Open: It opens the cursor.
3) Fetch: It fetches the rows into variables.
4) Close: Release the data within the cursor.
c) Write a PL/SQL program to find the square of a number given by user using while loop.
Ans:Set Serveroutput On
Declare
I number;
Square number;
Count number;
Begin
I:=&I;
Count:=0;
Square:=0;
While(count<I)
Square:=Square + I;
Count:=Count + I;
Dbms_output.put_line(“Square of Number is”||Square);
End loop;
End;
d) Explain looping in PL/SQL.
Ans:-There are three types of loops in PL/SQl:1) Simple loop:LOOP
e.g. LOOP
[program statements]
i:=i+1;
If condition THEN
if(i>10) then exit
EXIT;
end if;
END IF;
end loop
[Additional program statements]
END LOOP
2) For loop:FOR counter variable IN start_value..end_value
LOOP
program statements
END LOOP;
E.g.:
For Loop
For I IN 0..10 LOOP
Dbms_output.put_line(i)
END LOOP
3) While loop:WHILE condition LOOP
Program statements
END LOOP;
9
E.g.:
While LOOP
i:=0;
WHILE(i<=10)LOOP
i:=i+1;
Dbms_output.put_line(i)
END LOOP;
e) Differentiate between functional dependencies and multi valued dependencies.
Ans:Sr.no Functional dependency
Multivalued dependency
1.
A functional dependency
occurs when one attribute in a
relation uniquely determine
another attribute.
2.
This can be written A-->B
Multivalued dependency is a
dependency where one
attribute value is potentially a
“Multivalued Fact” about
another.
This can be written A-->>B
3.
A-->B states B is functionally
dependent upon A.
It cannot determine same types
of tuples.
A-->>B states A
multidetermines column B
It determine same types of
tuples.
4.
f) Consider the following database.
Employee(emp_id, emp_name, emp_city, emp_addr, emp_dept, join_date)
1) Display the names of employee in capital letters.
2) Display the emp_id of employee who lives in city pune and Mumbai.
3) Display the details of employee whose joining date is after ’01-Apr-1997’
4) Display the total number of employees whose dept_no is ‘10’.
Ans:1) Select upper(emp_name) from employee;
2) Select emp_id from employee where city=’pune’ or city=’mumbai’;
3) Select * from employee where join_date>’01-Apr-1997’;
4) Select emp_dept, count(emp_id) from employee where emp_dept=10 group by emp_dept;
10
5. Attempt any FOUR of the following:
a) Describe variable length record representation in files using byte string representation?
Ans:-Variable length record arise in database system in several ways:1) Storage of multiple record types in file.
2) Record types that allows variables lengths for one or more fields.
3) Record type that allows multiple files.
Byte String Representation:A simple method for implementing variable length record is to attach a special end of record
symbol to the end of each record. We can then store each record as a string of consecutive bytes.
The byte string representation has some disadvantages:
1) It is not easy to use the space occupied formerly by a deleted record.
2) There is no space in general for record to grow longer.
Thane
A-102
400
A-201
Kalyan
A-305
350
┴
900
A-218
700
┴
Dombivali A-215
700
A-110
500
┴
b) Explain the terms specialization and generalization with suitable example.
Ans:Specialization:1) Top down design process; we designate subgrouping within an entity set that are distinctive
from other entities in the set.
2) These sub grouping becomes lower level entity sets that have attribute or participate in
relationship that do not apply to the higher level entity set.
3) Depicted by a triangle component labeled ISA
4) Attribute inheritance:-A lower level entity set inherits all the attributes and relationship
participation of higher level entity set to which it is linked.
Generalization:1)
A bottom up design process combine a number of entity sets that share the same features into
a higher level entity set.
2) Specialization and generalization are simple inversion of each other they are represented in
ER diagram in the same way.
3) The terms specialization and generalization are used interchangeably.
c) Explain multi granularities locking scheme in brief.
Ans:Multiple Granularities:Granularities:11
The quality of being composed of relatively large particles i.e. records.
This allows data item of various sizes and defines a hierarchy of data granularities where small
granularities are nested within larger once. This can be represented graphically as a tree.
The levels in the tree where locking is done are:1) Fine granularities give high concurrency (lower in tree).
2) Coarse granularities give low concurrency (higher in tree).
DB
A1
Fa
Ea1
A2
Fc
Fb
Ea2
Ea3
Ea4
Ea5
The highest level in the example is entire database and level below are type:1) Area
2) File
3) Records
d) What do you mean by lock based protocol? Explain two phase locking protocol.
Ans:Lock Based Protocols:Locking protocols is a set of rules followed by all transactions while requesting and releasing
lock.
Locking protocols restricts set of possible schedule.
One way to ensure the Serializability is to require the data items must access in a mutual
exclusive manner.i.e. while one transaction is accessing data item, no other transaction can
modify the data items.
12
The most common method used to implement this requirement is to allow transaction access a
data item.
There are two modes in which a data item may be lock:1) Shared lock:In this lock a data item can only be read. It is requested using lock-s instruction.
2) Exclusive lock:Data item can be read as well as write. It is requested using lock-x instruction.
a) Two Phase Locking Protocols:It ensure Serializability this protocol requires that each transaction issue locked and unlocked
request in two phase.
1) Growing phase:The transaction may obtained locks but may not release any locks.
2) Shrinking phase:A transaction may released locks but not obtained any new lock.
Initially a transaction is in growing phase. Transaction acquires the locks as needed. Once
transaction released a lock it enter in the shrinking phase and it can issue no more lock request.
Cascading rollback is also possible in two phase locking protocols. To avoid this a modified
protocol called
two phase locking protocol is used. In this protocol a transaction must hold
all its a exclusive locks till it commit or abort.
Another modified protocol is rigorous protocol. In this protocol all locks are held till commit or
abort
e) List and explain function of DBA.
Ans:Functions of DBA: Schema definition
 Storage structure and access method definition
 Schema and physical organization modification
 Granting of authorization for data access
 Regular maintenance
1) Schema definition:- The DBA creates the original database schema by executing a set of
data definition statement in DDL.
2) Storage structure and access method definition:- The storage of data structure and how to
access data from it is handled by DBA.
3) Schema and physical organization modification:- DBA carry out the changes to the
schema and physical organization to reflect the changing needs of the organization. DBA
can alter the physical organization to improve the performance.
4) Granting of authorization for data access:- DBA grants different types of authorization.
i.e. DBA regulates which part of database can access by which user.
5) Regular maintenance:- DBA periodically backing up the database. Checking for free
space availability on disk for normal operation. Backing up to the data on the storage
13
devices to restore whenever required. Monitoring day to day activity which takes place
on network.
f) Describe ACID properties of transaction.
Ans:It is a logical unit of work and possibly updates data items after every transaction should be in
consistence state.
Transaction is consist of all operation executed between begin and end transaction. To ensure the
integrity data base system maintain ACID property of transaction.
Transaction property:ACID
1) Atomicity
2) Consistency
3) Isolation
4) Durability
1) Atomicity:Either all operation of the transaction are proper reflected in a database or none of these.
2) Consistency:Its property of transaction implies that if the database was in consistent state. Before the start
of transaction then on termination of transaction the transaction will also in a consistent state.
Execution of transaction in isolation preserves the consistency of database.
3) Isolation:Although multiple transaction may be executed concurrently, each transaction is unaware of
the other transaction to executing concurrently in the system.
This property of transaction indicates that the action performs by the transaction will be
hidden from other transaction or until the transaction terminates.
4) Durability:It ensures thatonce a completes success changes it has made to database remain permanent
even if system gets failed.
6. Attempt any TWO of the following:
a) List and describe various RAID levels.
Ans:RAID:- Redundant Arrays Of Independent Disks.
The levels of RAID’s are as follows:1) RAID Level 0:-block stripping; not redundant; used in high performance application where
data loss is critical.
2) RAID Level 1:-mirrored disk with blocking striping; offers best write performance; popular
for application such as storing log files in a database system.
3) RAID Level 2:-memory style error correcting codes with bit stripping.
4) RAID Level3:-bit interleaved parity; a single bit parity is enough for error correction, not just
detection, since we know which disk has failed.
14
5) RAID Level 4:-block interleaves parity; uses block level stripping and keeps a parity block on
a separate disk for corresponding blocks from N other disks.
6) RAID Level 5:-block interleaved distributed parity among all N +1 disks, rather than storing
data in N disks and parity in 1 disk.
7) RAID Level 6:-P + Q Redundancy scheme; similar to level 5, but stores extra redundant
information to guard against multiple disk failure. Better reliability than level 5 at higher
cost; not used as widely.
b) List and explain the types of integrity constraints in details.
Ans:1. Domain Integrity Constraint:It checks whether value entered in the row is from the given range of values or not.
There are two types of domain integrity constraint:o Not Null
o Check
a. Not Null Constraint:It is used to avoid the absence of value in a row for a particular column. Not null
constraint can be specified at the time of table creation or after the table creation with
alter table command.
Syntax:At the time of table creation
Create table table_name(column_name1 datatype (size) not null, column_name n
datatype (size));
Example:Create table emp(emp_idnumber(5) not null,emp_namevarchar(10));
b. Check Constraints:It is used to avoid unnecessary values to the columns. This constraints defines the
condition that each row must satisfy.
Syntax:At the time of table creation
Create table table_name(column_name1 datatype (size)constraintconstrain_name
check(condition));
Example:Create table bill (bill_nonumber(10),bill_amount number(5,2) constraint ABCD
check(bill_amount!=0.00));
2. Entity Integrity Constraint
15
An entity is any data recorded or stored in the database. Each database represent the table and
each row of the table represents an instants.
There are two types of entity integrity constraints:i. Unique Constraint
ii. Primary Constraint
a) Unique Key Constraint:It avoids the duplication of rows values of a specified column in a table. Duplication
of values does not result in maintaining integrity rather it creates problems while
maintaining database integrity and consistency.
Column define with the constraint can also allow null value.
SYNTAX
At the time of table creation
Create table table_name(column_name 1 datatype(size) constraint
constraint_nameunique,column_name n datatype(size));
Example
Create table employee(emp_id number(5) constraint abcd unique, emp_name
varchar2(10));
b) Primary Key Constraint:It is used to identify record uniquely. The primary key types of constraints enforces two
types of constraints:

There should not be duplication of value i.e. unique
The value should not be null i.e. not null constraint
SYNTAX
At the time of table creation
Create table table_name(column_name 1 datatype(size) Constraint constraint_name
primary key, column_name n datatype(size));
Example
Create table employee (emp_idnumber(5), constraint ABCD primary key, emp_name
varchar2(10));
16
3. Referential Integrity Constraint:It is used to establish relationship between parent and child table. Primary key is defined in
child table. The important concept associated wirh the referential integrity is foreign key
concept.
For e.g. considerthe employee table and department table. The common key or column in
both tables is department number. The department table contain department number as
primary key.
When primary key of department table is included in employee table then the link between
two table get automatically created.
When primary key of department table is included in employee table then the link between
two table get automatically created.
In this case department is parent table and employee is child table.
SYNTAX
At the time of table creation
Create table table_name(column1 dataype(size) references parent_table_name (primary key
attribute),column n dataype(size));
Alter table table_name add constraint constraint_name foreign key(primary key attribute)
references parent_table name(primary key attribute);
Referential Integrity Constraint On Delete Cascade:A foreign key with on delete cascade if a record in a parent table is deleted than
corresponding record in a child table will be automatically deleted. This deletion is known as
cascadedelete.
On delete cascade RDBMS tells that when parent row gets deleted from the parent table then
as children rows should get deleted from child table.
SYNTAX
Create table table_name (column 1 datatype(size) references parent_table_name (primary key
attribute) on delete cascade,column n datatype (size));
c) Describe various stages of query processing.
Ans:parser
and
translator
17
Query
Relational Algebra
Expression
Optimizer
Query Output
Evaluation
Engine
Execution Plan
1. Parser and Translator:Translator translates the query into its internal form. This is less
translated into relational algebra expression.
Parser checks the syntactical error and it verifies the relation.
2. Evaluation:Query execution engine takes query evaluation plan, executes that plan
and returns the answer to the query.
A sequence of operation that can be used to evaluate a query evaluation plan.
3. Optimization:It means to modify and achieve maximum efficiency in storage capacity or time or cost.Query
optimization is the process of selecting the most efficient query evaluation plan from among the
many strategies for a given query.
Optimization occurs at the relational algebra level where the system attempts to find an
expression, but more efficient to execute.
18