Dbms Unit 1 Bca 1 Notes For Dbms
Dbms Unit 1 Bca 1 Notes For Dbms
Syllabus
Introduction: An overview of database management system, database system Vs file system,
Characteristics of database approach, DBMS architecture, data models, schema and instances,
data independence.
Data Modeling using Entity Relationship Model: Entity, Entity types, entity set, notation for ER
diagram, attributes and keys, Concepts of composite, derived and multivalued attributes, Super
Key, candidate key, primary key, relationships, relation types, weak entities, enhanced E-R and
object modeling, Sub Classes:, Super classes, inheritance, specialization and generalization.
Introduction
Database systems have become an essential component of everyday life in modern society and in
that many frequently occurring activities involve the accessing of at least one database. e.g in
Finance, in University, in library searches, in bank transactions, in hotel/airline/Railway
reservations, in grocery store purchases, in online (Web) purchases etc.
Databases: The term database is a collection of all inter-related data. The major feature of
database is that the actual data are separated by the programs that use that data. A database must
have the following properties:
• It is a logically coherent collection of data, to which some meaning can be attached.
• It represents some aspect of the real (or an imagined) world, called
the miniworld or Universe of Discourse (UOD). Changes to the miniworld are reflected
in the database. For example, a UNIVERSITY miniworld concerned with students,
courses, course sections, grades, and course prerequisites.
• It is designed, built and populated with data for a specific purpose. There is an intended
group of users and some preconceived applications in which these users are interested.
A computerized database system may be created and maintained either by a group of application
programs or by database management systems.
A manual system on the other hand may be generated and maintained manually. E.g. the library
card catalog-based systems used in library.
A database can be of any size and of varying complexity. e.g. one person's recipe database) to
being huge/complex (e.g., Amazon's database that keeps track of all its products, customers, and
suppliers now contains storage above 2 TB).
In the database approach, a single repository of data is maintained that is defined once and then
accessed by various users. While in the file processing system, any changes to the structure of a
file may require changing all programs that access the file.
Definition: A database management system (DBMS) is a collection of interrelated data and a set of
programs to access those data. Hence a DBMS is a general purpose software system that provides an
environment that is both convenient and efficient to use in each of the following (with respect to a
database):
i. Defining a database involves specifying the data types, structures and constraints for
the data to be stored in the database.
ii. Constructing a database is the process of storing the data on some medium (e.g.,
magnetic disk) that is controlled by the DBMS.
iii. Manipulating a database includes functions such as
a) Querying the database to retrieves some specific data
b) Updating the database i.e insertions, deletions and modifications to its content that
reflects changes in the mini world.
c) Generating reports from data.
iv. Sharing allowing multiple users and programs to access the database
"simultaneously".
v. System protection preventing database from becoming corrupted when hardware or
software failures occur.
vi. Security protection preventing unauthorized or malicious access to database.
Database system
A database together with the DBMS software is referred to as a database system shown in fig
1.1 below:
Figure 1.1: A simplified database system environment
Mini-world: Some part of the real world about which data is stored in a database. Eg. student
grades and transcripts at a university.
Example of a Database (with a Conceptual Data Model)
• Mini-world for the example:
• Part of a UNIVERSITY environment.
• Some mini-world entities:
• STUDENTs
• COURSEs
• SECTIONs (of COURSEs)
• (academic) DEPARTMENTs
• INSTRUCTORs
Some mini-world relationships:
• SECTIONs are of specific COURSEs
• STUDENTs take SECTIONs
• COURSEs have prerequisite COURSEs
• INSTRUCTORs teach SECTIONs
• COURSEs are offered by DEPARTMENTs
• STUDENTs major in DEPARTMENTs
DBMS ARCHITECTURE
The idea was first described by the ANSI/SPARC committee in late 1970's.
Also called ANSI/SPARC architecture or Three-Schema architecture.
The purpose of DBMS is to provide user interface with an abstract view of the data called
Data Abstraction.
A DBMS can be organized into 3 separate levels of abstraction.
Mappings
• The process of transforming requests and results between levels are called
mapping. Programs refer to an external schema, and are mapped by the DBMS to
the internal schema for execution. 2 types of mappings are required in a database
system with 3 different views:
• mapping between external/conceptual (providing logical data independence)
• mapping between conceptual/internal (providing physical data independence)
The main advantage of Three-schema architecture is that it provides data independence. Data
independence is the ability to change the schema at one level of the database system without
having to change the schema at the other levels. Data independence is of two types,
namely, logical data independence and physical data independence.
• Logical data independence: It is the ability to change the conceptual schema without
affecting the external schemas or application programs. The conceptual schema may be
changed due to change in constraints or addition of new data item or removal of existing
data item, etc., from the database. The separation of the external level from the
conceptual level enables the users to make changes at the conceptual level without
affecting the external level or the application programs. For example, if a new data item,
say Edition is added to the BOOK file, the two views (view 1 and view 2) shown in the
Figure below are not affected.
• Physical data independence: It is the ability to change the internal schema without
affecting the conceptual or external schema. An internal schema may be changed due to
several reasons such as for creating additional access structure, changing the storage
structure, etc. The separation of internal schema from the conceptual schema facilitates
physical data independence.
To understand the three-schema architecture, consider the three levels of the BOOK file
in Online Book database as shown in figure below. In this figure, two views (view 1 and view 2)
of the BOOK file have been defined at the external level. Different database users can see these
views. The details of the data types are hidden from the users. At the conceptual level,
the BOOK records are described by a type definition. The application programmers and the
DBA generally work at this level of abstraction. At the internal level, the BOOK records are
described as a block of consecutive storage locations such as words or bytes. The database users
and the application programmers are not aware of these details; however, the DBA may be aware
of certain details of the physical organization of the data.
Fig. Three levels of Online Book database (BOOK file)
Logical data independence is more difficult to achieve than the physical data independence
because the application programs are always dependent on the logical structure of the database.
Therefore, the change in the logical structure of the database may require change in the
application programs.
DATA MODELS
Data Model
• A collection of concepts/conceptual tools that can be used to describe the structure of a
database means the data types, relationships, and constraints that should hold on the
data.
• Also includes basic operations for specifying retrievals and updates on the database.
• Provide concepts that describe details of how data is stored in the computer.
• Meant for computer specialists, not for typical end users.
10
- The database schema changes very infrequently. The database state changes every time the
database is updated.
- Schema is also called intension. State is also called extension.
Database Users
Users may be divided into:
1. Actors on the Scene- Those who actually use and control the content. The jobs involve the
day-to-day use of a large database. They are:
• Database Administrators
• Database Designers
• End Users
• System Analysts and Application Programmers (Software Engineers)
• Database Administrators - DBA is a kind of database user with the following
responsibilities:
1. The primary responsibility of the Database Administrator (DBA) is to observe and
manage (administer) the various resources (database itself, DBMS software and other
related software).
11
2. Workers behind the Scene : We consider people who may be called "workers
behind the scene"—those who work to maintain the database system environment,
12
but who are not actively interested in the database itself. They include the following
categories:
• DBMS system designers and implementers are persons who design and
implement the DBMS modules and interfaces as a software package. A DBMS is a
complex software system that consists of many components or modules, including
modules for implementing the catalog, query language, interface processors, data
access, concurrency control, recovery, and security. The DBMS must interface
with other system software, such as the operating system and compilers for various
programming languages.
• Tool developers include persons who design and implement tools—the software
packages that facilitate database system design and use, and help improve
performance. Tools are optional packages that are often purchased separately. They
include packages for database design, performance monitoring, natural language or
graphical interfaces, prototyping, simulation, and test data generation.
• Operators and maintenance personnel are the system administration personnel
who are responsible for the actual running and maintenance of the hardware and
software environment for the database system.
13
• Loading data stored in files into a database. Includes data conversion tools.
• Backing up the database periodically on tape.
• Reorganizing database file structures.
• Report generation utilities.
• Performance monitoring utilities.
• Other functions, such as sorting, user monitoring, data compression, etc.
14
In the ER model, the main concepts are entity, attribute, and relationship.
15
16
17
has three attributes: Name, Headquarters, and President; their values are "Sunco Oil," "Houston,"
and "John Smith," respectively.
18
• The Null value: In some cases a particular entity might not have an applicable value for
a particular attribute Or that value may be unknown. Example: The
attribute DateOfDeath is not applicable to a living person and its correct value may be
unknown for some persons who have died. In such cases, we use a special attribute value
(non-value), called null.
19
employees. These employee entities share the same attributes, but each entity has its own
value(s) for each attribute.
Entity type : An entity type defines a collection (or set) of entities that have the same attributes.
Each entity type in the database is described by its name and attributes. The figure below shows
two entity types, named EMPLOYEE and COMPANY, and a list of attributes for each. A few
individual entities of each type are also illustrated, along with the values of their attributes.
Entity set : The collection of all entities of a particular entity type in the database at any point in
time is called an entity set; the entity set is usually referred to using the same name as the entity
type. For example, EMPLOYEE refers to both a type of entity as well as the current set of all
employee entities in the database.
An entity type is represented in ER diagrams (Figure 3.2) as a rectangular box enclosing the
entity type name. Attribute names are enclosed in ovals and are attached to their entity type by
straight lines. Composite attributes are attached to their component attributes by straight lines.
Multivalued attributes are displayed in double ovals.
An entity type describes the schema or intension for a set of entities that share the same
structure. The collection of entities of a particular entity type are grouped into an entity set,
which is also called the extension of the entity type.
Key Attributes of an Entity Type
An important constraint on the entities of an entity type is the key or uniqueness constraint on
attributes. An entity type usually has an attribute whose values uniquely identifies each
individual entity in the collection. Such an attribute is called a key attribute, and its values can
be used to identify each entity uniquely. For example, in a STUDENT entity rollno is the key
attribute because no 2 students have the same roll numbers. In ER diagrammatic notation, each
key attribute has its name underlined inside the oval.
Some entity types have more than one key attribute. E.g. Entity Type CAR with two keys and a
corresponding Entity Set
20
Unique Key: A unique key is an attribute or a set of attributes of a relation schema used to
uniquely identify each row in a relation. It may contain null value.
Super Key: A superkey is a set of one or more attributes that taken collectively, allows us
uniquely identify a row in a relation . eg {empno}, {empno,name}, {empno,deptno},
{name,deptno} etc all these sets are super key.
Candidate Key: A candidate key is a minimal set of attributes necessary to identify a row. It is
also called a minimal superkey. Examples of superkeys in this schema would be {empno},
{empno, Name}, {empno, Name, job}, and {empno, Name, deptno} etc.
In a real database we do not need values for all of those attributes to identify row. We only need,
for our example, the set {empno}. This is a minimal superkey—that is, a minimal set of
attributes that can be used to identify a single row. Therefore, empno is a candidate key.
21
A Relationship type R among n entity types E1, E2, ..., En defines a set of associations or a
relationship set-among entities from these entity types. Mathematically the relational set R is a set of
relationship instances ri
Relationship instance ri
• Each ri associates n individual entities (e1, e2, ..., en)
• Each entity ej in ri is a member of entity set Ej
• Relationships uniquely identified by keys of participating entities.
In the figure belowemployees e1, e3, and e6 work for department d1; employees e2 and e4 work
for department d2 and e5 and e7 work for d3.
22
23
24
1. One to One: An entity in A is associated with exactly one entity in B. And one entity in B
is associated with exactly one entity in A.
25
2. One to Many: An entity in A is associated with any no. of entities in B. An entity in B can
be associated with at most one entity in A.
3. Many to One: An entity in A is associated with at most one entity in B. An entity in B can
be associated with any no. of entity in A.
4. Many to Many: An entity in A is associated with any no. of entities in B. An entity in B can
be associated with any no. of entities in A.
Figure:
a. 1 : 1 b. 1 : M c. M : 1 d. M : M
26
1: M( ONE TO MANY)
M : 1(MANY TO ONE)
27
M : M(MANY TO MANY)
Subclass - Often an Entity has many subgrouping which are meaningful and need to be
explicitly represented. These are called subclasses.
Superclass - Is the term used to describe the Entity that contains a subclass(s).
Example: EMPLOYEE entity type is grouped into SECRETARY, ENGINEER, MANAGER,
TECHNICIAN, SALARIED_EMPLOYEE, HOURLY_EMPLOYEE.
28
29
It is not necessary that every entity in a superclass be a member of some subclass. Subclass is
shown with an arc on the line pointing toward the superclass. EER diagram also has "d"
(disjoint) in circle denoting unique specialization.
Example: SECRETARY (as well as TECHNICIAN and ENGINEER) inherit the attributes
Name, SSN, …, from EMPLOYEE. Every SECRETARY entity will have values for the
inherited attributes.
Generalization
The reverse of the specialization process
• Generalization takes common features of subclasses and creates a superclass.
• Example: CAR, TRUCK generalized into VEHICLE; both CAR, TRUCK become
subclasses of the superclass VEHICLE.
30
31