16
Page 1 Dr.SNS RAJALAKSHMI COLLEGE OF ARTS AND SCIENCE (AUTONOMOUS) Accredited With “A” Grade by NAAC An ISO 9001-2008 Certified Institution (Recognized by UGC, Approved by AICTE, NEW DELHI and Affiliated to Bharathiar University, Coimbatore) 2012-2013 DEPARTMENT OF COMMERCE WITH COMPUTER APPLICATIONS RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED BY DEPARTMENT OF COMMERCE WITH COMPUTER APPLICATIONS

RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 1

Dr.SNS RAJALAKSHMI COLLEGE OF ARTS AND SCIENCE

(AUTONOMOUS)

Accredited With “A” Grade by NAAC

An ISO 9001-2008 Certified Institution

(Recognized by UGC, Approved by AICTE, NEW DELHI and

Affiliated to Bharathiar University, Coimbatore)

2012-2013

DEPARTMENT OF COMMERCE WITH COMPUTER APPLICATIONS

RELATIONAL DATABASE MANAGEMENT SYSTEMS

PREPARED BY

DEPARTMENT OF COMMERCE WITH COMPUTER APPLICATIONS

Page 2: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 2

Relational Database Management System

Objective: On successful completion of this subject the students should have Knowledge on database management systems and build a solid foundation for advanced studies in database area. UNIT I:

Introduction: purpose of the database system – view of data – data models – database languages – transaction management – storage management – database administrator – database users. Entity-Relationship

models: basic concepts – design issues – mapping constraints – keys – E-R diagram – weak entity sets – Extended E-R features.

UNIT II:

Relational Model: Structure of relational databases – the relational algebra - the tuple relational calculus - the domain relational calculus. Relational Database Design: Pitfalls in relational-database design – decomposition – normalization using fundamental dependencies - Distributed Databases: distribution transaction model – commit protocols – concurrency control. UNIT III:

Oracle Tables: DDL: Naming Rules and conventions – Data Types – Constraints – Creating Oracle Table – Displaying Table Information – Altering an Existing Table – Dropping, Renaming, Truncating Table – Table Types – Spooling – Error codes. UNIT IV:

Working with Table: Data Management and Retrieval: DML – adding a new Row/Record – Customized Prompts – Updating and Deleting an Existing Rows/Records – retrieving Data from Table – Arithmetic Operations – restricting Data with WHERE clause –Sorting – Revisiting Substitution Variables – DEFINE command – CASE structure. Functions and Grouping: Built-in functions –Grouping Data. Multiple Tables: Joins and Set operations: Join – Set operations. UNIT V:

PL/SQL: A Programming Language: History – Fundamentals – Block Structure – Comments – Data Types – Other Data Types – Declaration – Assignment operation – Bind variables – Substitution Variables – Printing – Arithmetic Operators. Control Structures and Embedded SQL: Control Structures – Nested Blocks – SQL in PL/SQL – Data Manipulation –Transaction Control statements. PL/SQL Composite Data Types: Records – Tables – Varrays.

Page 3: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 3

Text Book(s): 1. Henry F.Korth, Abraham Silberschatz & S. Sudarshan, “Database System Concepts”, Tata McGraw-Hill, 2010. (Unit-I, II) 2. Nilesh Shah, “Database Systems Using Oracle”, 2nd edition, PHI, 2008(Unit-III, IV, V) Reference Book(s): 1. Rajesh Narang, “Database Management Systems”, PHI, 2006. 2. Gerald V.Post, “Database Management Systems”, Tata McGraw-Hill, Sixth Reprint, 2008

Page 4: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 4

UNIT I

Introduction

Database Management System (DBMS)

DBMS contains information about a particular enterprise

Collection of interrelated data

Set of programs to access the data

An environment that is both convenient and efficient to use

Database Applications:

Banking: all transactions

Airlines: reservations, schedules

Universities: registration, grades

Sales: customers, products, purchases

Online retailers: order tracking, customized recommendations

Manufacturing: production, inventory, orders, supply chain

Human resources: employee records, salaries, tax deductions

Databases touch all aspects of our lives

Purpose of Database Systems

In the early days, database applications were built directly on top of file

systems

Drawbacks of using file systems to store data:

Data redundancy and inconsistency

Multiple file formats, duplication of information in different files

Difficulty in accessing data

Need to write a new program to carry out each new task

Data isolation — multiple files and formats

DATA BASE SYSTEM

Database system is nothing more than a computer-based record keeping system

(i.e.) a system whose overall purpose is to record and maintain information.

The database system involves four major components. They are data, hardware,

software and users.

Page 5: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 5

Database Management System

Fig: Simplified picture of a database system

Data

The data stored in the system is partitioned into one or more databases.

Integrated:

The database can be thought of as a unification of several distinct files,

with the redundancy among those files eliminated.

Example: Combination of EMPLOYEE and ENROLLMENT data files.

Shared:

Individual pieces of data in the database can be shared among different

users that is many users can have access to the same piece of data.

Example: The department information in EMPLOYEE file

would be shared by users in the personal department,

education department etc.

Hardware

The hardware consists of the secondary storage device disks, drums,etc…

Software

It is a set of programs used to accomplish a task.

Users

*application programmers

*end-users

*DBA

1.Application programmers

Application programmer is responsible for writing application programs

that use the database.

2.End-users

Page 6: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 6

End-users access the database from a terminal.

3.Database Administrator

The person who has such control over the system is called DBA.The

main functions of DBA are

*Schema definition

*Storage structure and access-method definition

*Granting and physical-organization modification

*Integrity-constraint specification

These are the various components of a database system.

Operational data

A database is a collection of stored operational data used by the application systems of some

particular enterprise.

Examples. Manufacturing company, Bank, Hospital, University, Government

department etc.

Example for the illustration of operational data

Consider the manufacturing company where the enterprise will wish to

retain information about the projects it has on hand; parts used in those projects; the suppliers

who supply the parts; the warehouses in which the parts are stored; the employees who work

on the projects etc.,

These are the basic entities about which data is recorded in the database. In general

there will be associations or relationships linking the basic entities together(entity is any

distinguishable object).

For example, there is an association between suppliers and parts that is each supplier

supplies certain parts and conversely each part is supplied by certain suppliers etc..

Fig: An example of operational data

The figure illustrates

1. Most of the associations are between two entities or more than that

ex., arrow connecting suppliers-parts-projects

Here supplier s2 supplies part p4 to project j3.

2. The example also shows one arrow involving only in one type of entity (parts)

ex., some parts are components of other parts (a screw is a component of a huge assembly

or char etc..)

3. Some entities may be associated in more than one relationship

Projects Suppliers

Department

s

Parts Employees Warehouses

Locations

Page 7: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 7

Ex., projects and employees are linked in two relationships

A. the employee works on the project

B .the employee is the manager of the project

This example clearly illustrates operational data and its functions.

Data Independence

The ability to modify a schema definition in one level without affecting a schema in

the next higher level is called data independence.

Two types of data independence stated are

1. Physical data independence

Physical data independence is the ability to modify the physical schema

without causing application programs to be rewritten.

Example,

Modifying the structure of the database using ALTER command etc.

2. Logical data independence

Logical data independence is the ability to modify the logical schema

without causing the application programs to be rewritten.

Example,

Modifications such as adding new columns or field to the database.

Most of the modifications are done by the DBA and the types of change

that the DBA wish to make may be explained with the help of the

following definitions:

Stored field: Stored field is the smallest unit of data stored in the database.

Ex., database containing information about parts would probably include a stored field type

called part number etc.

Stored record: Stored record is a named collection of associated stored fields.

Stored file: Stored file is the collection of all occurrences of one type of stored

record.

Similarly if a data type of the stored field has to be changed is also done by

Data.

The data storage may be in any of the following form.

1. Representation of numeric data

Data may be stored in internal arithmetic form or as a character string.

2. Representation of character data

A character field may be stored in any of several character codes

(eg.EBCDIC,ASCII..)

3. Units for numeric data

The units in a numeric field may change.Ex.,from inches to centimeters

4. Data coding

In some situations it may be desirable to represent data in storage by coded values.

Ex., the value for part color=RED can be interpreted as 1=’RED’.

5. Structure of stored records

Two existing types of stored record may be combined into one. For ex., the record

types(part number, color) and (part number, weight) may be integrated to give

(part number,color,weight).

Also a single type of stored record may be split into two. For ex.,(part

number,color,weight) may be broken down into (part number, color) and (part

number, weight).

6. Structure of stored fields

Page 8: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 8

A given stored file may be physically implemented in storage in a wide variety of

ways.

For ex: storing the file in single storage volume or spread across several volumes.

The above fact implies that the database is able to grow without affecting existing

applications.

Architecture for a Database system

The architecture is divided into three general levels; they are internal, conceptual, external

levels,

…………………………….

External level

(Individual user views)

Conceptual level (Community

user view)

Internal level (Storage

view)

Fig: Three levels of architecture

Internal level(Physical level)

The storage view is described by means of the internal schema which not only

defines the various stored record types but also specifies what indexes exist, how

stored files are represented, what physical sequence the stored records are in and so

on.

Conceptual level (Community logical level)

This level is the representation of the entire information content of the database.

External level(user logical level)

This level is closest to the users and is concerned with the way the data is seen by

the individual users.

For example,

A user from the Personnel Department might view the details of employee and department

and nothing else.

Detailed System architecture

Page 9: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 9

fig: Database system architecture

Mappings

The mappings involved in the architecture are conceptual/internal mapping and

external/conceptual mappings.

The conceptual/internal mapping defines the correspondence between the

conceptual view and stored database.

The external/conceptual mapping defines the correspondence between a particular

external view and the conceptual view.

Database administrator(DBA)

Thus the DBA is responsible for the overall control of the system in technical level. The

major tasks of DBA are

Defining the conceptual schema or schema definition

Storage structures and access-method definition

Schema and physical organization modification

Granting of authorization for data access

Integrity constraint specification

DBMS

The DBMS is the software that handles all access to the database. Its functions are as

follows

A user issues an access request using some particular data sub language

The DBMS intercepts that request and analyses it.

The DBMS inturn,intercepts the external schema for that user, the corresponding

external/conceptual mapping, the conceptual schema, the conceptual/internal

mapping, the storage structure definition.

The DBMS executes the necessary operations on the stored database

Page 10: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 10

The diagrammatic representation of the major functions of DBMS and its components.

Distributed databases

Distributed processing means that distinct machines can be connected

together into communication network such as the Internet, so that the single data-

processing task can span several machines in the network.

For example, consider a banking system in which the customer accounts database is

distributed across the bank branch offices, such that each individual customer account

record is stored at the customer’s local branch.

Advantages

Efficiency of local processing

Data sharing

Disadvantages Overhead may be quite high

Technical difficulties

Page 11: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 11

Storage structures and its purposes.

The main idea behind data maintenance is for future reference and it has to be stored for the

storage and access of data ,various techniques like sequential ,direct access etc. exists.

Once the data is stored in the memory in internal level(physical storage) then it is

accessed through DML operations.

The component responsible for this internal/physical conversion is called an access

method.

The access method consists of a set of routines whose function is to conceal all

device-dependent details from the DBMS and to present the DBMS with a stored

record interface.

Fig: The stored record interface

The stored record interface allows DBMS to view the storage structure as a collection

of stored files each consisting of all occurrences of one type of stored record. The

DBMS knows

What stored files exist

The structure of the corresponding stored record

The stored fields on which it is sequenced

The stored field which can be used for direct access etc.

This information will be specified as part of the storage structure definition.

The DBMS does not know

a) Anything about physical records

b) How sequencing is performed

c) How direct access is performed

These informations are specified to the access method not to the DBMS.

Also, when a new stored record occurrence is first created and entered into the database, the

access method is responsible for assigning it a unique stored record address(SRA).

How data are stored in the physical storage?

Page 12: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 12

There are various possible representations of data within

the memory and some of them are explained here.

Consider the

following example.

The above example is the simplest form of data representation containing

only five record occurrences with unique supplier number.

If the suppliers are 10000 rather than five and located in only 10 different

cities then the storage will be wasted specifying the 10 cities among 10000

suppliers.

Then the pointer is specified from the supplier file to the city file by

separating the city attribute alone to a file.

The following is another form of data the representation

Supplier file

City File

City

Athens

London

Paris

indexed on city

An example,”Find all suppliers in a given city”,when this query is placed then the result is

retrieved quite easily from the database if represented as above that is in indexed form.

DATA STRUCTURES AND CORRESPONDING OPERATORS

The range of data structures supported at the user level is a factor that critically affects many

componenets of the system

Relational approach

Hierarchical approach

Network approach

S# Sname Status City

S1 Smith 20 London

S2 Jones 10 Paris

S3 Blake 30 Paris

S4 Clark 20 London

S5 Adams 30 Athens

S# Sname Status City-ptr

S1 Smith 20

S2 Jones 10

S3 Blake 30

S4 Clark 20

S5 Adams 30

City Supplier ptr

Athens

London

paris

S# Sname Status

S1 Smith 20

S2 Jones 10

S3 Blake 30

S4 Clark 20

S5 Adams 30

Page 13: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 13

The relational approach

The relational approach uses a collection of tables to represent both data and the

relationships among those data.

Sample relational database

Bank customer

Accounts

account-no balance

A-101

A-215

A-102

A-305

A-201

A-217

A-222

500

700

400

350

900

750

700

For example, customer Johnson whose social-security-no. is 192-83-7465 lives on Alma in

Palo Alto and has 2 accounts A-101 with balance 500,a-201 with balance 900.Also smith and

Jhonson shares A-201 account.

Network model

Data in the network model are represented by collections of records and

relationships among data . The relationships among data can be represented

by links, which can be viewed as pointers

Sample network databases

Hierarchical Model

This form of data representation is similar to network model in the sense that

records represent data and relationships among data and links.

Customer name social-security-no. customer-street customer-city account-no.

Johnson 92-83-7465 Alma Palo Alto A-101

Smith 019-28-3746 North Rye A-215

Hayes 677-28-9011 Main Harrison A-102

Turner 182-73-6091 Putnam Stamford A-305

Johnson 192-83-7465 Alma Palo Alto A-201

Jones 321-12-3123 Main Harrison A-217

Lindsay 336-66-9999 Park Pits field A-222

Smith 019-28-3746 North Rye A-201

Johnson 192-83-7465 Alma Palo Alto A-101 500

A-215 700 Smith 019-28-3746 North Rye

Page 14: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 14

It differs from the network model in that the records are organized as

collection of trees rather than graphs.

Advantages of using DBMS

Many enterprises choose to store its operational data in an integrated database

because it provides the enterprise with centralized control of its operational data,

which is most valuable.

DBA has the central responsibility over operational data.

Advantages if data is stored under centralized control.

QUESTIONS

ONE MARKS:

1. RDBMS refers to _________database

a)Rational b)Ring c)Relational d)Region

2. Data values stored in a database must satisfy certain______

a) Rules b)Constraints c)Conventions d)Data

3. The collection of information stored in a database at a particular moment is called

_________ of the database

a)Schema b)View c)instance d)Data independence

4.Overall design of the database is called the database__________

a)View b)Schema c)Abstraction d)Independence

5. ________ models are used in describing data at logical and view level

a)Object based b)Physical c)Record based d)Functional

6. The collection of basic object is called as __________

a)attribute b)entity c)relationship d)variables

7. The relational model uses collection of _________

a)records b)tables c)columns d)trees

8. Data in the network model uses collection of _______

a)Trees b)Tables c)Columns d)Links

9. A data dictionary contains _______

a)data b)data about data c)tables d)records

10. A __________ is a collection of operations that performs a single logical function in a

database application

a)data b)transaction c)file d)table

11.The__________ is responsible for the interaction with file manager

a)DML b)DDL c)Storage manager

12. Overall logical structure of a database can be expressed graphically by ____

Page 15: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 15

a)Rectangles b)Ellipses c)ER diagram d)Diamonds

13.A person who have central control over the system is called ________

a)Storage manager b)File manager c)Application programmers d)DBA

14. __________ one computer professionals who interact with the system through DML calls

a)naïve users b)application programmers c)specialized uses d)sophisticated users

15. _________ users interact with the system without writing programs

a) specialized b)naïve uses c)sophisticated users d)application programmers

16. __________ is a language that enables users to access or manipulate data

a)DDL b)DML c)Database d)Procedure

17. __________ express the number of entities to which another entity can be associated via

relationship set

a)attributes b)mapping cardinalities c)relationship d)schema

18. An entity in A is associated with at most one entity in B then it is a ______ relationship

set

a)one to one b)many to one c)many to many d)one to many

19.An entity in A is associated with any number of entities in B and entity in B is associated

with any number of entities in A then it __________ relationship

a))one to one b)one to many c)many to many d)many to one

20.An entity set that does not have sufficient attributes to from a primary key then it is

________ entity set

a)strong b)weak c)strong and weak d)relationship set

21. Data that is processed and is relevant

a)Data base b)Information c) Data d) Knowledge

22. In E-R Diagram the entities are represented by

a) Rectangular box b) Ellipse c) Triangle d) Square

23. A database schema is specified by a special language called

a) DDL b) DML c)Query language d) none

24. Single column is used as unique identifier is known as

a)Primary key b) Foreign key c) Super key d) Candidate key

25. In a database there are entities that cannot exists by themselves. Such entities are known

as ________ entities.

a) Weak b) Strong c)Network d)Relational

FIVE MARKS:

1. List the difference between file system and database system.

2. Explain the mapping constraints briefly.

3. Explain the purpose of the database system.

4. What is mean transaction processing?

Page 16: RELATIONAL DATABASE MANAGEMENT SYSTEMS PREPARED …

Page 16

5. Explain E-R model with example.

6. What are the important functions of RDBMS?

7. Mention the types of attributes.

8. Write short notes relationships

9. Explain the difference between physical and logical independence.

10. Illustrate the difference between

11. a)three levels of abstraction & b)between a schema and instance

12. Explain the distinctions among primary key, candidate key and super key

13. Differences between weak and strong entity set

14. Analyze the concept and merits of RDBMS.

15. Write short notes on database users

EIGHT MARKS:

1. Discuss categories on data models.

2. Explain the transaction management.

3. Create an E-R diagram to represent your college.

4. List the Responsibilities of a database manager?

5. We can convert any weak entity set to a strong entity set by simply adding

appropriate attributes. Why then do we have weak entity set.

6. Explain the concept and importance of views