Sei sulla pagina 1di 29

GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG

DLAk1MLN1 CI CCMU1Lk SCILNCL


kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

DATABASE MANAGEMENT SYSTEM


(FOR BOTH CSE-4
TH
-SEM/MECH-3
RD
SEM DEPARTMENT)
MODULE-1

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

Purpose of Database Systems

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

GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

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
Integrity problems
Integrity constraints (e.g. account balance > 0) become buried in
program code rather than being stated explicitly
Hard to add new constraints or change existing ones Databases touch all
aspects of our lives

DBMS Architecture
Different abstract levels
- a widely accepted general architecture for a database
- database described by three abstract levels
- internal schema (physical database)
- conceptual schema (conceptual database)
- external schema (view) Objectives
- insulation of application programs and data
- support of multiple user views
- use of schema to store the DB description (mete-data)

The Three Schema Architecture :
External schema
- describes a subset of the database that a particular user group is interested
in, according to the format the format user wants, and hides the rest
- may contain virtual data that is derived from the files, but is not explicitly
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

stored Conceptual schema


- hides the details of physical storage structures and concentrates on
describing entities, data types, relationships, operations, and constraints.
Internal schema
- describes the physical storage structure of the DB
- uses a low-level (physical) data model to describe the complete details of
data storage and access paths

THREE-LEVEL ARCHITECTURE


GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

EXTERNAL LEVEL (highest level)


The users view of the database.
Consists of a number of different external views of the DB.
Describes part of the DB for particular group of users.
Provides a powerful and flexible security mechanism by hiding parts of the
DB from certain users. The user is not aware of the existence of any attributes
that are missing from the view.
It permits users to access data in a way that is customized to their needs, so
that the same data can be seen by different users in different ways, at the
same time.

CONCEPTUAL LEVEL
The logical structure of the entire database as seen by DBA.
What data is stored in the database?
The relationships among the data.
Complete view of the data requirements of the organization, independent of
any storage consideration.
Represents:
- entities, attributes, relations
- constraints on data
- semantic information on data
- security, integrity information
Supports each external view: any data available to a user must be contained
in or derivable from the conceptual level.

INTERNAL LEVEL
Physical representation of the DB on the computer.
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

How the data is stored in the database.


Physical implementation of the DB to achieve optimal run time
performance and storage space utilization.
- Storage space allocation for data and indexes
- Record description for storage
- Record placement
- Data compression, encryption

PHYSICAL LEVEL
Managed by the OS under the direction of the DBMS.

SCHEMAS, MAPPINGS, INSTANCES
DB schema: overall description of the DB.
Three different schemas according to the level of abstraction.
DBMS: mapping between schemas consistency of schemas
Conceptual/Internal Mapping: to find the actual record (combinations) in
physical storage that constitutes a logical Record in the conceptual schema.

External/Conceptual Mapping: map names in the users view
Onto the relevant part of the conceptual schema.
Instances and Schemas
Similar to types and variables in programming languages
Schema the logical structure of the database
l Example: The database consists of information about a set of customers and
accounts and the relationship between them)
l Analogous to type information of a variable in a program
l Physical schema: database design at the physical level
l Logical schema: database design at the logical level
Instance the actual content of the database at a particular point in time
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

l Analogous to the value of a variable



Database instance: the data in the DB at any particular point in time.

DATA INDEPENDENCE
The ability to modify a scheme definition in one level without Affecting a
scheme definition in a higher level is called data independence.
1. There are two kinds:
Logical data independence
The ability to modify the conceptual scheme without causing application
programs to be rewritten.
Immunity of external schemas to changes in the conceptual schema.
Usually done when logical structure of database is altered


GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

Physical data independence


The ability to modify the internal scheme without having to change the
conceptual or external schemas.
Modifications at this level are usually to improve performance.

Three Schema Architecture
Data and meta-data: - three schemas are only meta-data (descriptions of data)
- data actually exists only at the physical level Mapping
- DBMS must transform a request specified on an external schema into a
request against the conceptual schema, and then into the internal schema
- requires information in meta-data on how to accomplish the mapping
among various levels
- overhead (time-consuming) leading to inefficiencies
- few DBMSs have implemented the full three-schema architecture

Benefits of Three Schema Architecture:
Logical data independence
- The capacity to change the conceptual schema without having to change
external schema or application programs ex: Employee (E#, Name, Address,
and Salary) A view including only E# and Name is not affected by changes in
any other attributes.
Physical data independence
- the capacity to change the internal schema without having to change the
conceptual (or external) schema
- internal schema may change to improve the performance (e.g., creating
additional access structure)
- easier to achieve logical data independence, because application programs
are dependent on logical structures
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n


Data Models
Data abstraction
- one fundamental characteristic of the database approach
- hides details of data storage that are not needed by most database users and
applications
Data model
- a set of data structures and conceptual tools used to describe the structure of
a database (data types, relationships, and constraints)
- used in the definition of the conceptual, external, and internal schema
- must provide means for DB designers to represent the real-world
information completely and naturally.

Data Models
High-level (conceptual) data models
- use concepts such as entities, attributes, relationships
- object-based models: ER model, OO model
Representational (implementation) data models
- most frequently used in commercial DBMSs
- record-based models: relational, hierarchical, network
Low-level (physical) data models
- to describe the details of how data is stored
- captures aspects of database system implementation: record structures
(fixed/variable length) and ordering, access paths (key indexing), etc.

Schemas and Instances
In any data model, it is important to distinguish between the description of
the database and the database itself. Database schema (meta-data)
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

- overall description of a database, specified by a set of definitions


- specified during database design (not change frequently)
- similar to the notion of type definition in programs Database instance
- current contents of the database (actual data): DB state
- may change frequently Distinction between database schema and database
state
- a database just specified (or defined) is in empty state
- initial state would be achieved when the data is loaded
- DBMS is responsible to ensure every database state is valid

Data Definition and Manipulation Languages
Data definition language (DDL)
- not a procedural language
- notations for describing the types of entities and relationships among
entities
DDL statements -- data dictionary
Data manipulation language (DML)
- for accessing and modifying data
- non-procedural: specifying "what" to access
- procedural: specifying "what" and "how" to get
- non-procedural languages could be easy to use but may not be efficient

Database Administrator
Coordinates all the activities of the database system; the database
administrator has a good understanding of the enterprises information
resources and needs.
Database administrator's duties include:
Schema definition
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

Storage structure and access method definition


Schema and physical organization modification
Granting user authority to access the database
Specifying integrity constraints
Acting as liaison with users
Monitoring performance and responding to changes in requirements
Data Models


DATA MODELS

Data models are a collection of conceptual tools for describing data, data
relationships, and data semantics and data constraints. Components: structural
part manipulative part integrity rules There are three different groups:
Object-based Data Models
Record-based Data Models
Physical Data Models

Describe data at the conceptual and external levels Describe data at the
internal level

Object-based Data Models
- Entity-relationship model.
- Object-oriented model.
- Semantic data model.
- Functional data model
Record-based Data Models
Named so because the database is structured in fixed format records of
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

several types.
Each record type defines a fixed number of fields, or attributes.
Each field is usually of a fixed length (this simplifies the implementation).
The three most widely accepted models are the
Relational, network, and hierarchical data model.
Physical Data Models
1. Are used to describe data at the lowest level.
2. Very few models, e.g.
Unifying model.
Frame memory.

Entity-relationship model
- popular high-level conceptual model used in DB design
- proposed by P. Chen in 1976 (ACM TODS)
- Perception of real-world consisting of a collection of entities and
relationships among them OO model.
- DB is defined in terms of objects, their properties, and their operations
(methods) Relational model
- represents a DB as a collection of tables Network model
- represents DB as record types and 1:N relationships Hierarchical model
- represents data as hierarchical tree structures
An entity may be defined as a thing which is recognized as being capable of
an independent existence and which can be uniquely identified. An entity is
an abstraction from the complexities of some domain.
E-R Diagram Notation:
Entity Key attributes

Weak Entity Multivalue
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

attribute
Relationship


Attributes Composite
Attributes
Relationship between two entities


ER Diagrams

Rectangles represent entity sets.
-Diamonds represent relationship sets.
-Lines link attributes to entity sets and entity sets to relationship sets.
-Ellipses represent attributes
-Double ellipses represent multivalve attributes.
-Dashed ellipses denote derived attributes.
-Underline indicates primary key attributes (will study later)



GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG


DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

ER Diagram With Composite, Multivalued, and Derived Attributes



Relationship Sets with Attributes:

OneToMany Relationship:




GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

ManyToOneRelationships:
In a many to one relationship a loan is associated with several (including
0) customers via borrower, a customer is associated with at most one
Loan via borrower.

ManyToMany Relationship:










GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

Specialization Example:

Entities: Entity-a thing (animate or inanimate) of independent physical or
conceptual existence and distinguishable. In the University database context,
an individual student, faculty member, a class room, courses are entities.

Entity Set or Entity Type-Collection of entities all having the same
properties. Student entity set collection of all student entities. Course entity
set collection of all course entities
Attributes - Each entity is described by a set of attributes/properties.
Student entity Stud Namename of the student.
Roll Numberthe roll number of the student.
Sexthe gender of the student etc. All entities in an Entity set/type have the
same set of attributes
Types of Attributes
Simple Attributes-having atomic or indivisible values.
example: Depta string Phone Numberan eight digit number
Composite Attributes-having several components in the value.
example: Qualification with components (Degree Name, Year, University
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

Name)
Derived Attributes-Attribute value is dependent on some other attribute.
Example: Age depends on Date Of Birth. So age is a derived attribute.
Single-valued-having only one value rather than a set of values.
-for instance, Place Of Birthsingle string value.
Multi-valued -having a set of values rather than a single value.
-for instance, Courses Enrolled attribute for student Email Address attribute
for student Previous Degree attribute for student.
Attributes can be:-simple single-valued, simple multi-valued,composite
single-valued or composite multi-valued

Diagrammatic Notation for Entities entity -rectangle attribute -ellipse
connected to rectangle multi-valued attribute -double ellipse composite
attribute -ellipse connected to ellipse derived attribute-dashed ellipse



Relationships
When two or more entities are associated with each other, we have an
instance of a Relationship.
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

E.g.: student Ramesh enrolls in Discrete Mathematics course


Relationship enrolls has Student and Course as the participating entity sets.
Tuples in enrollsrelationship instances
enrolls is called a relationship Type/Set.
ER Diagram for a Banking Enterprise:







GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

Summary off Symbolls Used iin ER Notation:



GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n


Cardinality Ratios/Mappings
One-to-one: An E1entity may be associated with at most one E2 entity and
similarly an E2entity may be associated with at most one E1 entity.
One-to-many: An E1entity may be associated with many E2entities whereas
an E2entity may be associated with at most one E1entity
.Many-to-one: ( similar to above)
Many-to-many: Many E1entities may be associated with a single E2 entity
and a single E1entity may be associated with many E2entities



GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

Key Attributes:
Primary Key: The primary key of a relational table uniquely identifies each
record in the table. It can either be a normal attribute that is guaranteed to be
unique (such as Social Security Number in a table with no more than one
record per person) or it can be generated by the DBMS.
Examples: Imagine we have a STUDENTS table that contains a record for
each student at a university. The student's unique student ID number would
be a good choice for a primary key in the STUDENTS table. The student's
first and last name would not be a good choice, as there is always the chance
that more than one student might have the same name.

Foreign Key:A foreign key is a field in a relational table that matches the
primary key column of another table. The foreign key can be used to cross-
reference tables
Referential Integrity
Referential integrity is a database concept that ensures that relationships
between tables remain consistent. When one table has a foreign key to
another table, the concept of referential integrity states that you may not add a
record to the table that contains the foreign key unless there is a
corresponding record in the linked table. It also includes the techniques
known as cascading update and cascading delete, which ensure that changes
made to the linked table are reflected in the primary table.
Referential integrity enforces the following three rules:
1. We may not add a record to the Employees table unless the Managed By
attributes points to a valid record in the Managers table.
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

2. If the primary key for a record in the Managers table changes, all
corresponding records in the Employees table must be modified using a
cascading update.
3. If a record in the Managers table is deleted, all corresponding records in
the Employees table must be deleted using a cascading delete.
Importance of Referential Integrity
By providing specification of columns within a referencing table that are
foreign keys for columns in some other referenced table, referential integrity
is a reliable mechanism which prevents accidental database corruptions when
doing inserts, updates, and deletes. It states that a row cannot exist in a table
with a non-null value for a referencing column if an equal value does not
exist in a referenced column.
Once we define the employee_number as a foreign key in employee_phone
relation, if we try to insert a row with a primary key value that does not exist
in employee table, the system will not allow this insertion.
The following summarize the benefits of referential integrity:
a) Ensure data integrity and consistency base on primary key and foreign key
b) Increases development productivity, because it is not necessary to code
SQL statements to enforce referential constraints, the Teradata RDBMS
automatically enforces referential integrity.
Candidate Key:
A candidate key is a combination of attributes that can be uniquely used to
identify a database record without any extraneous data. Each table may have
one or more candidate keys. One of these candidate keys is selected as the
table primary key.
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

Check Constraint:
A check constraint (also known as table check constraint) is a condition that
defines valid data when adding or updating an entry in a table of a relational
database. A check constraint is applied to each row in the table. The
constraint must be a predicate. It can refer to a single or multiple columns of
the table. The result of the predicate can be TRUE, FALSE, or UNKNOWN,
depending on the presence of NULLs. If the predicate evaluates to
UNKNOWN, then the constraint is not violated and the row can be inserted
or updated in the table.
Each check constraint has to be defined in the CREATE TABLE or ALTER
TABLE statement using the syntax:
1. CREATE TABLE table_name (...,CONSTRAINT constraint_name CHECK (
predicate ), ... )
2. ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK (
predicate )
NOT NULL Constraint:
A NOT NULL constraint is functionally equivalent to the following check constraint
with an IS NOT NULL predicate:CHECK (column IS NOT NULL)
Domain Constraints:
A domain is defined as the set of all unique values permitted for an attribute.
For example, a domain of date is the set of all possible valid dates, a domain
of integer is all possible whole numbers, a domain of day-of-week is
Monday, Tuesday ... Sunday.
This in effect is defining rules for a particular attribute. If it is determined that
an attribute is a date then it should be implemented in the database to prevent
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

invalid dates being entered.


A domain of possible values should be associated with every attribute. These
domain constraints are the most basic form of integrity constraint. They are
easy to test for when data is entered.
Domain types
1. Attributes may have the same domain, e.g. cname and employee-name.
2. It is not as clear whether bname and cname domains ought to be distinct.
3. At the implementation level, they are both character strings.
4. At the conceptual level, we do not expect customers to have the same
names as branches, in general.
5. Strong typing of domains allows us to test for values inserted, and
whether queries make sense. Newer systems, particularly object-oriented
database systems, offer a rich set of domain types that can be extended
easily.
Database Users:
Users are differentiated by the way they expect to interact with
the system
-Application programmers interact with system through DML calls
-Sophisticated users form requests in a database query language
-Specialized users write specialized database applications that do
not fit into the traditional data processing framework
-Nave users invoke one of the permanent application programs that
have been written previously
l Examples, people accessing database over the web, bank tellers,clerical staff


GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

Database Administrator
n Coordinates all the activities of the database system; the
database administrator has a good understanding of the Enterprises
information resources and needs.
Database administrator's duties include:
-Schema definition
-Storage structure and access method definition
-Schema and physical organization modification
-Granting user authority to access the database
-Specifying integrity constraints
-Acting as liaison with users
-Monitoring performance and responding to changes in
requirements
Keys:
-A super key of an entity set is a set of one or more attributes
whose values uniquely determine each entity.
-A candidate key of an entity set is a minimal super key
l Customer_id is candidate key of customer
l account_number is candidate key of account
-Although several candidate keys may exist, one of the candidate
keys is selected to be the primary key.






GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1
kLAkLD 8 Asst.rof.SAN1CSn

I|gure 1 L-k D|agram of (A|r||ne keservat|on System


L-k D|agram of Lmp|oyee ayro|| System:
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n
L-k D|agrams
A|r||ne keservat|on System)
GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
CI CCMU1Lk SCILNCL
kUMAk kA1n

GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG


DLAk1MLN1
kLAkLD 8 Asst.rof.SAN1CSn

L-k D|agram of Company:


GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG


CI CCMU1Lk SCILNCL
kUMAk kA1n

GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG


DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

L-k D|agram of Company

L-k D|agram of 8ooks Supp||er


GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

L-k D|agram of Student Informat|on System

L-k D|agram of L|brary Management System


GANDnI INS1I1U1L ICk LDUC1AICN & 1LCnNCLCG
DLAk1MLN1 CI CCMU1Lk SCILNCL
kLAkLD 8 Asst.rof.SAN1CSn kUMAk kA1n

Potrebbero piacerti anche