mi0034-dbms set1

13
 DATABASE MANAGEMENT SYSTEM MB 0034 Set 1  Name : Prem Kumar Singh Roll number : 521058995 Learning centre : 00964 Subject : DATABASE MANAGEMENT SYSTEM Assignment No. : Set 1

Upload: prem-singh

Post on 06-Apr-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

8/3/2019 MI0034-DBMS SET1

http://slidepdf.com/reader/full/mi0034-dbms-set1 1/13

 

DATABASE MANAGEMENT SYSTEM

MB 0034

Set 1

 Name : Prem Kumar Singh

Roll number : 521058995

Learning centre : 00964

Subject : DATABASE MANAGEMENT SYSTEMAssignment No. : Set 1

8/3/2019 MI0034-DBMS SET1

http://slidepdf.com/reader/full/mi0034-dbms-set1 2/13

MB0034 – DATABASE MANAGEMENT SYSTEM

Q1. Differentiate between Traditional File System & Modern Database System?

Describe the properties of Database & the Advantage of Database?

Ans:

Traditional File System Modern Database Management

Systems

Traditional File system is the system that was

followed before the advent of DBMS i.e., it is the

older way.

This is the Modern way which has

replaced the older concept of File

system.

In Traditional file processing, data definition is part

of the application program and works with only

specific application.

· Data definition is part of the DBMS

· Application is independent and can be

used with any application.File systems are Design Driven; they require

design/coding change when new kind of data

occurs.

 E.g.:: In a traditional employee the master file has

Emp_name, Emp_id, Emp_addr, Emp_design,

Emp_dept, Emp_sal, if we want to insert one more

column ‘Emp_Mob number’ then it requires a

complete restructuring of the file or redesign of the

application code, even though basically all the data

except that in one column is the same.

· One extra column (Attribute) can be

added without any difficulty

· Minor coding changes in the

Application program may be required.

Traditional File system keeps redundant [duplicate]

information in many locations. This might result in

the loss of Data Consistency.

For e.g.: Employee names might exist in separate

files like Payroll Master File and also in Employee

Benefit Master File etc. Now if an employee

changes his or her last name, the name might be

changed in the pay roll master file but not be

changed in Employee Benefit Master File etc. Thismight result in the loss of Data Consistency.

Redundancy is eliminated to the

maximum extent in DBMS if properly

defined.

In a File system data is scattered in various files,

and each of these files may be in different formats,

making it difficult to write new application

 programs to retrieve the appropriate data.

This problem is completely solved here.

Security features are to be coded in the Application

Program itself.

Coding for security requirements is not

required as most of them have been

taken care by the DBMS.

· Hence, a data base management system is the software that manages a database, and is

responsible for its storage, security, integrity, concurrency, recovery and access.

2

8/3/2019 MI0034-DBMS SET1

http://slidepdf.com/reader/full/mi0034-dbms-set1 3/13

MB0034 – DATABASE MANAGEMENT SYSTEM

· The DBMS has a data dictionary, referred to as system catalog, which stores data about

everything it holds, such as names, structure, locations and types. This data is also referred to

as Meta data.

Properties of Database

The following are the important properties of Database:

1. A database is a logical collection of data having some implicit meaning. If the data are not

related then it is not called as proper database. E.g. Student studying in class II got 5 th rank.

Stud_name Class Rank obtained

Vijetha Class II 5th

2. A database consists of both data as well as the description of the database structure and

constraints.

E.g.

Field Name Type Description

Stud_name Character It is the student’s name

Class Alpha numeric It is the class of the student

3. A database can have any size and of various complexity. If we consider the above example

of employee database the name and address of the employee may consists of very few

records each with simple structure. E.g.

Emp_name Emp_id Emp_addr Emp_desig Emp_Sal

Prasad 100 “Shubhodaya”, Near  

Katariguppe Big Bazaar,

BSK II stage, Bangalore

Project

Leader 

40000

Usha 101 #165, 4th main

Chamrajpet, Bangalore

Software

engineer 

10000

 Nupur 102 #12, Manipal Towers,

Bangalore

Lecturer 30000

Peter 103 Syndicate house,Manipal

IT executive 15000

Like this there may be ‘n number of records.

4. The DBMS is considered as general-purpose software system that facilitates the process of 

defining, constructing and manipulating databases for various applications.

5. A database provides insulation between programs, data and data abstraction. Data

abstraction is a feature that provides the integration of the data source of interest and helps to

leverage the physical data however the structure is.

3

8/3/2019 MI0034-DBMS SET1

http://slidepdf.com/reader/full/mi0034-dbms-set1 4/13

MB0034 – DATABASE MANAGEMENT SYSTEM

6. The data in the database is used by variety of users for variety of purposes. For E.g. when

you consider a hospital database management system the view of usage of patient database is

different from the same used by the doctor. In this case the data are stored separately for the

different users. In fact it is stored in a single database. This property is nothing but multiple

views of the database.

7. Multiple user DBMS must allow the data to be shared by multiple users simultaneously.

For this purpose the DBMS includes concurrency control software to ensure that the updation

done to the database by variety of users at single time must get updated correctly. This

 property explains the multiuser transaction processing.

Q2. What is the disadvantage of sequential file organization? How do you overcome it?

What are the advantages & disadvantages of Dynamic Hashing?

Ans: In sequential file organization records are arranged in physical sequence by the value of 

some field, called the sequence field. Often the field chosen is a key field, one with unique

values that are used to identify records. The records are simply laid out on the storagedevices, often magnetic tape, in increasing or decreasing order by the value of the sequence

field.

For example IBM's sequential Access Method SAM among others, uses this organization.

This organization is simple, easy to understand and easy to manage but is best for providing

sequential access, retrieving records on faster another in the same order in which they are

stored. It is not good for direct or random access, which means picking out a particular 

record; because it generally requires that we pass over prior records in order to find the target

record.

It is also not possible to insert a new record in the middle of the file. Sequential is the oldest type of 

file organization and despite its shortcomings is well suited for certain applications. In sequential file

organization records arranged like in physical positions. Retrieving records take much time.

We can physically order the records of a file on disk based on the values of one of their fields called

the ordering field. This leads to an ordered or sequential file. Records are placed in an order in

sequential file and that's why it is totally different from unordered files where records are stored in the

order in which they are inserted, it means that if new records are inserted then they took place at the

end of file. Sequential files have many advantages as given below.

* To find a record in the sequential file is very efficient, because all files are stored in an order and no

sorting is required.

* Finding the next record from a current record is also very efficient and it does not require additional  block access as the next record is in the current record.

* If we use a technique like Binary Search, then it becomes more efficient and easy to search a record.

While on the other hand if we search a record in an unordered file then we have to check the whole

file because records are stored in no order in unordered file. Sequential files are also known as Sorted

files.

Dynamic Hashing In dynamic hashing, the access structure is built on the binary

representation of the hash value. In this, the number of buckets is not fixed [as in regular 

hashing] but grows or diminishes as needed. The file can start with a single bucket, once that

 bucket is full, and a new record is inserted, the bucket overflows and is slit into two buckets.

The records are distributed among the two buckets based on the value of the first [leftmost] bit of their hash values. Records whose hash values start with a 0 bit are stored in one bucket,

4

8/3/2019 MI0034-DBMS SET1

http://slidepdf.com/reader/full/mi0034-dbms-set1 5/13

MB0034 – DATABASE MANAGEMENT SYSTEM

and those whose hash values start with a 1 bit are stored in another bucket. At this point, a

 binary tree structure called a directory is built. The directory has two types of nodes.

1. Internal nodes: Guide the search, each has a left pointer corresponding to a 0 bit, and a

right pointer corresponding to a 1 bit.

2. Leaf nodes: It holds a pointer to a bucket – a bucket address.

Each leaf node holds a bucket address. If a bucket overflows, for example: a new record is

inserted into the bucket for records whose hash values start with 10 and causes overflow, then

all records whose hash value starts with 100 are placed in the first split bucket, and the

second bucket contains those whose hash value starts with 101. The levels of a binary tree

can be expanded dynamically.

Advantages of dynamic hashing:

1. The main advantage is that splitting causes minor reorganization, since only the records inone bucket are redistributed to the two new buckets.

2. The space overhead of the directory table is negligible.

3. The main advantage of extendable hashing is that performance does not degrade as the file

grows. The main space saving of hashing is that no buckets need to be reserved for future

growth; rather buckets can be allocated dynamically.

Disadvantages:

1. The index tables grow rapidly and too large to fit in main memory. When part of the index

table is stored on secondary storage, it requires extra access.

2. The directory must be searched before accessing the bucket, resulting in two-block access

instead of one in static hashing.

3. A disadvantage of extendable hashing is that it involves an additional level of indirection.

Q 3. What is relationship type? Explain the difference among a relationship instance,

relationship type & a relation set?

Ans: Relationships: In the real world, items have relationships to one another. E.g.: A book 

is published by a particular publisher. The association or relationship that exists between the

entities relates data items to each other in a meaningful way. A relationship is an association

 between entities.

A collection of relationships of the same type is called a relationship set.

A relationship type R is a set of associations between E, E2…..En entity types

mathematically, R is a set of relationship instances ri.

5

8/3/2019 MI0034-DBMS SET1

http://slidepdf.com/reader/full/mi0034-dbms-set1 6/13

MB0034 – DATABASE MANAGEMENT SYSTEM

E.g.: Consider a relationship type WORKS_FOR between two entity types – employee and

department, which associates each employee with the department the employee works for.

Each relationship instance in WORKS_FOR associates one employee entity and one

department entity, where each relationship instance is ri which connects employee and

department entities that participate in ri.

Employee el, e3 and e6 work for department d1, e2 and e4 work for d2 and e5 and e7 work 

for d3. Relationship type R is a set of all relationship instances.

Figure 5.4: Some instances of the WORKS_FOR relationship

Degree of relationship type: The number of entity sets that participate in a relationship set.

A unary relationship exists when an association is maintained with a single entity.

A binary relationship exists when two entities are associated.

A tertiary relationship exists when there are three entities associated.

Figure 5.5: Degree of relationship type

Role Names and Recursive Relationship

Each entry type to participate in a relationship type plays a particular role in the relationship.

The role name signifies the role that a participating entity from the entity type plays in each

relationship instance, e.g.: In the WORKS FOR relationship type, the employee plays the role

of employee or worker and the department plays the role of department or employer.

However in some cases the same entity type participates more than once in a relationship

type in different roles. Such relationship types are called recursive.

E.g.: employee entity type participates twice in SUPERVISION once in the role of supervisor and once in the role of supervisee.

6

8/3/2019 MI0034-DBMS SET1

http://slidepdf.com/reader/full/mi0034-dbms-set1 7/13

MB0034 – DATABASE MANAGEMENT SYSTEM

Self Assessment Question(s) (SAQs) (For Section 4.4)

Define Relationship set, role.

Constraints on Relationship Types

Relationship types usually have certain constraints that limit the possible combination of 

entities that may participate in the relationship instance.

E.g.: If the company has a rule that each employee must work for exactly one department.

The two main types of constraints are cardinality ratio and participation constraints.

The cardinality ratio specifies the number of entities to which another entity can be associatedthrough a relationship set.

Mapping cardinalities should be one of the following.

One-to-One: An entity in A is associated with at most one entity in B and vice versa.

Employee can manage only one department and that a department has only one manager.

One-to-Many: An entity in A is associated with any number in B. An entity in B however 

can be associated with at most one entity in A.

Each department can be related to numerous employees but an employee can be related to

only one department

Many-to-One: An entity in A is associated with at most one entity in B. An entity in B

however can be associated with any number of entities in A. Many depositors deposit into asingle account.

Man-to-Many: An entity in A is associated with any number of entities in B and an entity in

B is associated with any number of entities in A.

An employee can work on several projects and several employees can work on a project.

7

8/3/2019 MI0034-DBMS SET1

http://slidepdf.com/reader/full/mi0034-dbms-set1 8/13

MB0034 – DATABASE MANAGEMENT SYSTEM

Participation Roles: There are two ways an entity can participate in a relationship where

there are two types of participations.

1. Total: The participation of an entity set E in a relationship set R is said to be total if every

entity in E participates in at lest one relationship in R. Every employee must work for a

department. The participation of employee in WORK FOR is called total.

Figure 5.6: Some instances of the WORKS_FOR relationship

Total participation is sometimes called existence dependency.

2. Partial: If only some entities in E participate in relationship in R, the participation of 

entity set E in relationship R is said to be partial.

Figure 5.7: Some instances of the WORKS_FOR relationship

We do not expect every employee to manage a department, so the participation of employee

in MANAGES relationship type is partial.

Weak Entity: Some entity types may not have any key attribute of their own; they are called

weak entity types. An entity set that has a primary key is termed as a strong entity type. A

weak entity type always has a total participation [existence dependence] with respect to a

strong entity.

A weak entity type is dependent on the existence of another entity. Weak entity is also

referred to as child, dependent OR subordinate entities, and strong entities as parent, owner 

OR dominant entities. E.g.: In the following relationship PARENT is a weak entity as it

needs the entity EMPLOYEE for its existence. The entities EMPLOYEE, COMPANY etc.

are strong entities. Weak entities are represented by a double lined rectangle.

8

8/3/2019 MI0034-DBMS SET1

http://slidepdf.com/reader/full/mi0034-dbms-set1 9/13

MB0034 – DATABASE MANAGEMENT SYSTEM

Q 4. What is SQL? Discuss.

Ans: In this unit you study about the Structured Query language which is used for 

 programming the database. The history of SQL began in an IBM laboratory in San Jose,

California, where SQL was developed in the late 1970’s. SQL stands for structured QueryLanguage. It is a non-procedural language, meaning that SQL describes what data to retrieve

delete or insert, rather than how to perform the operation. It is the standard command set used

to communicate with the RDBMS.

A SQL query is not-necessarily a question to the database. It can be command to do one of 

the following.

· Create or delete a table.

· Insert, modify or delete rows.

· Search several rows for specifying information and return the result in order.

· Modify security information.

The SQL statement can be grouped into following categories.

1. DDL (Data Definition Language)

2. DML (Data Manipulation Language)

3. DCL (Data Control Language)

4. TCL (Transaction Control Language)

DDL: Data Definition Language

The DDL statement provides commands for defining relation schema i,e for creating tables,

indexes, sequences etc. and commands for dropping, altering, renaming objects.

DML: (Data Manipulation Language)

The DML statements are used to alter the database tables in some way. The UPDATE,

INSERT and DELETE statements alter existing rows in a database tables, insert new records

into a database table, or remove one or more records from the database table.

DCL: (Data Control Language)

The Data Control Language Statements are used to Grant permission to the user and Revoke

 permission from the user, Lock certain Permission for the user.

SQL DBA>Revoke Import from Akash;

SQL DBA>Grant all on emp to public;

9

8/3/2019 MI0034-DBMS SET1

http://slidepdf.com/reader/full/mi0034-dbms-set1 10/13

MB0034 – DATABASE MANAGEMENT SYSTEM

SQL DBA>Grant select, Update on EMP to L.Suresh;

SQlDBA>Grant ALL on EMP to Akash with Grant option;

Revoke: Revoke takes out privilege from one or more tables or views.

SQL DBA>rEOKE UPDATE, DELETE FROM l.sURES;

SQL DBA>Revoke all on emp from Akash

TCL: (Transaction Control Language)

It is used to control transactions.

Eg: Commit

Rollback: Discard/Cancel the changes up to the previous commit point.

Q 5. What is Normalization? Discuss various types of Normal Forms?

Ans: Normalization is the process of efficiently organizing data in a database. There are two goals of the normalization process: eliminating redundant data (for example, storing the same data in morethan one table) and ensuring data dependencies make sense (only storing related data in a table).Both of these are worthy goals as they reduce the amount of space a database consumes and ensurethat data is logically stored.

The Normal Forms

The database community has developed a series of guidelines for ensuring that databases arenormalized. These are referred to as normal forms and are numbered from one (the lowest form of normalization, referred to as first normal form or 1NF) through five (fifth normal form or 5NF). Inpractical applications, you'll often see 1NF, 2NF, and 3NF along with the occasional 4NF. Fifth normalform is very rarely seen and won't be discussed in this article.

Before we begin our discussion of the normal forms, it's important to point out that they are guidelinesand guidelines only. Occasionally, it becomes necessary to stray from them to meet practicalbusiness requirements. However, when variations take place, it's extremely important to evaluate anypossible ramifications they could have on your system and account for possible inconsistencies. Thatsaid, let's explore the normal forms.

First Normal Form (1NF)

First normal form (1NF) sets the very basic rules for an organized database:

• Eliminate duplicative columns from the same table.

• Create separate tables for each group of related data and identify each row with a uniquecolumn or set of columns (the primary key).

Second Normal Form (2NF)

Second normal form (2NF) further addresses the concept of removing duplicative data:

• Meet all the requirements of the first normal form.

• Remove subsets of data that apply to multiple rows of a table and place them in separate

tables.

10

8/3/2019 MI0034-DBMS SET1

http://slidepdf.com/reader/full/mi0034-dbms-set1 11/13

MB0034 – DATABASE MANAGEMENT SYSTEM

• Create relationships between these new tables and their predecessors through the use of foreign keys.

Third Normal Form (3NF)

Third normal form (3NF) goes one large step further:

• Meet all the requirements of the second normal form.

• Remove columns that are not dependent upon the primary key.

Fourth Normal Form (4NF)

Finally, fourth normal form (4NF) has one additional requirement:

• Meet all the requirements of the third normal form.

• A relation is in 4NF if it has no multi-valued dependencies.

Remember, these normalization guidelines are cumulative. For a database to be in 2NF, it

must first fulfill all the criteria of a 1NF database.

Q6. What do you mean by Shared Lock & Exclusive lock? Describe briefly two phase

locking protocol? 

Ans: Shared Locks: It is used for read only operations, i.e., used for operations that do not

change or update the data.

E.G., SELECT statement:,

Shared locks allow concurrent transaction to read (SELECT) a data. No other transactions

can modify the data while shared locks exist. Shared locks are released as soon as the data

has been read.

Exclusive Locks: Exclusive locks are used for data modification operations, such as

UPDATE, DELETE and INSERT. It ensures that multiple updates cannot be made to the

same resource simultaneously. No other transaction can read or modify data when locked by

an exclusive lock.

Exclusive locks are held until transaction commits or rolls back since those are used for write

operations.

There are three locking operations: read_lock(X), write_lock(X), and unlock(X). A lock 

associated with an item X, LOCK(X), now has three possible states: "read locked", "write-

locked", or "unlocked". A read-locked item is also called share-locked, because other 

transactions are allowed to read the item, whereas a write-locked item is called exclusive-

locked, because a single transaction exclusive holds the lock on the item.

Each record on the lock table will have four fields: <data item name, LOCK, no_of_reads,

locking_transaction(s)>. The value (state) of LOCK is either read-locked or write-locked.

read_lock(X):

11

8/3/2019 MI0034-DBMS SET1

http://slidepdf.com/reader/full/mi0034-dbms-set1 12/13

MB0034 – DATABASE MANAGEMENT SYSTEM

B, if LOCK(X)=’unlocked’

end

else if LOCK(X)="read-locked"

then no_of_reads(X)¬no_of_reads(X)+1

else begin wait(until)LOCK(X)="unlocked" and

the lock manager wakes up the transaction);

goto B

end;

write_lock(X):

B: if LOCK(X)="unlocked"

Then LOCK(X)¬"write-locked";

else begin

wait(until LOCK(X)="unlocked" and

the lock manager wkes up the transaction);

goto B

end;

unlock(X):

if LOCK(X)="write-locked"

Then begin LOCK(X) "un-locked";

Wakeup one of the waiting transctions, if any

end

else if LOCK(X)=read-locked"

then begin

12

8/3/2019 MI0034-DBMS SET1

http://slidepdf.com/reader/full/mi0034-dbms-set1 13/13

MB0034 – DATABASE MANAGEMENT SYSTEM

no_of_reads(X) no_of_reads(X)-1

if no_of_reads(X)=0

then begin LOCK(X)=unlocked";

wakeup one of the waiting transactions, if any

end

end;

13