0% found this document useful (0 votes)
9 views146 pages

4 DBMS-2

Uploaded by

ppghoshin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views146 pages

4 DBMS-2

Uploaded by

ppghoshin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 146

DBMS : System

Concepts

A Database is a well-organized collection of


data that are related in a meaningful way
which can be accessed in different logical
orders but are stored only once.
DBMS : System
Concepts

A Database 

Is assumed that operations (like update, insert, retrieve, etc.)


on the database can be carried out in a simple and flexible
way. Also since a database tends to be a long-term resource
of an organization, it is expected that planned as well as
unplanned applications can (in general) be carried out
without great difficulty.

We can therefore, say that the data in the database


is persistent, integrated, structured and shared.
DBMS : System
Concepts
What is Integrated Data

A database can be considered to be a unification


of several distinct data files and when any
redundancy among those files are eliminated
the data is said to be integrated data .
DBMS : System
Concepts
What is Shared Data

A database contain data that can be shared by different


users for different applications simultaneously. Such
simultaneous use does not affect the correctness of the
data. Data can be shared in three different levels.

• Sharing data between different functional units in an


organization.
• Sharing data between different levels of users.
• Sharing data between different locations.
DBMS : System
Concepts
What is Persistent Data

If some processes enters the data into the database


then it can be subsequently removed from the
database only by some explicit request to remove.
Then the data is said to persistent. It can not be
removed from the database as a side effect of some
other process, which does not carry any specific
request to delete this data.
DBMS : System
Concepts
What is Persistent Data

Since data is a valuable resource for any enterprise, often


a great deal of money is spent, collecting, storing and
maintaining data. The running of an enterprise may
depend on proper maintenance of its operational data.

The end users & the application programmers develop


programs uses the database to retrieve information
needed in their work.
Database System
A database system (also called as database
management system or DBMS) consist of a
collection of interrelated data and a set of programs
to access that data. It is a software that assists in
maintaining and utilizing a database.

In simple terms, a database system is nothing more


than a computerized record-keeping system.
Database System : Concept &
Meaning
A database management system (DBMS) consists of
• A collection of interrelated data and persistent data.
This part of DBMS is usually referred to as the database (DB)
• A set of application programs used to access, update
and manage that data. This portion forms the data
management system (MS)

But both are the goals of DBMS?


The DBMS has to provide an environment that is both
convenient and efficient to use in
• retrieving information from the database; and
• storing information into the database.
Database System : Concept &
Architecture

Functionalities of DBMS

Database systems are usually designed to manage


large bodies of information. This involves

• Data modeling which is related to definitions of structures for


information storage
• File & System Structure, Query Processing which provides the
mechanisms for the manipulation of information
• Crash Recovery & Security which provides the safety of information
in the database
• Concurrency Control which maintains the correctness of data while
allowing concurrent access by multiple users
The Advantages of DBMS
• Centralized Data Management
• Data Independence
• System Integration
• Data Independence
• Redundancies & Inconsistencies can be Reduced
• Better Service to the Users
• Flexibility of the System is Improved
• Cost of Developing & Maintaining systems is Lower
• Standards can be Enforced
• Securities can be Improved
• Integrity can be Improved
• Enterprise requirements can be Improved
The Disadvantages of using a DBMS

• Confidentiality, Privacy and Security


• Data Quality
• Data Integrity
• Enterprise Vulnerability
• The Cost of using a DBMS
Database languages
In order to provide the various facilities of DBMS to different types of
users, DBMS provides one or more specialized programming languages
called as Database Languages.
A language is needed to describe the database to the DBMS as well as
provide facilities for changing the database and for defining and for
changing physical data structures.

Another language is needed for manipulating and retrieving data stored


in DBMS.
These languages are called
Data description languages (DDL)
Data Manipulation Languages (DML)
Data Description Languages (DDL)

It is used to describe the details of the data. DBMS will have a


compiler whose function is to process DDL statements in order to
identify & store the descriptions (Conceptual Schema) as a set of
tables in the Data Dictionary. Thus Data Dictionary is a file which
contains the data about the data or Metadata.

Another language, the Storage Definition language (SDL) is used


to specify the Internal Schema. The mapping between the two
languages can be specified by any one of the languages.
Data Manipulation Languages (DML)
Once the database schemas are compiled and the database is
populated with data, users must have some means for
manipulating the database. The language that enables users to
access or manipulate data is called the DML.

By data manipulation, we mean the following.


• The retrieval of information stored in the database
• The insertion of new information into the database
• The deletion of information from the database
• The modification of information stored in the database

DML are of following two types.


• Procedural DML which require users to specify what data are
needed and how to get those data
• Nonprocedural DML which require a user to specify what data
are needed without specifying how to get it.
The Languages come in the following two forms.
• Extended Host languages These are subroutine calls from one or
more programming languages. The programming language that
is extended is usually called the Host Language.
Language
• Query Languages These are special purpose languages that
usually provide more powerful facilities to interact with the
database. These languages are often designed to be simple so
that non-programmers may se them.
Database System : Concept &
Architecture
Database Administrator (DBA)
The Database Administrator is a person having central control over data and the
programs accessing the data.

The Responsibilities of a DBA.


• Authorizing access to the Database
• Coordinating & Monitoring its use
• Acquiring S/w & H/w resources as needed
Database System : Concept &
Architecture
The Tasks of Database Administrator (DBA)
The Database Administrator has to carry out certain important tasks.

The Tasks of a DBA.


• Deciding & Loading the Database Contents
• Assisting & Approving Applications & Access
• Deciding Data Structures
• Backup & Recovery
• Monitor Actual Usage
The other duties of a DBA
• Defining security & integrity checks
• Monitoring performance & responding to changing requirements
• Liaising with users
Database System : Concept &
Architecture
Database Designers

The Database Designers are Responsible for


• Identifying the data to be stored in the Database
• Choosing appropriate structures to represent and store the
data
The Responsibilities of Database Designers are
• Schema Definition
• Storage Structure & Access Method Definition
• Schema & Physical organization modification
Database System : Concept &
Architecture
Database Users

Other than DBA & Database Designers, who mostly uses the Database
• Application Programmers
• End-users
The various types of end-users are are
• Sophisticated end-users
• Specialized end-users
• Naive end-users
• System Analysts
Dealing with various Front-end & Back-end applications with the
database, where DBMS itself acts as the backend application tool
Database System : Concept &
Architecture
Database Manager

The Database Manager is not an individual but a program


module which provides the interface between the low-level
data stored in the database and the application programs
and queries submitted to the system.
The Database Manager module is responsible for all the
following tasks
• Interaction with the file manager
• Integrity Enforcement
• Security Enforcement
• Backup and Recovery
Data Processing

22
Data Storage Hierarchy

23
Concept of Primary Key &
Secondary Key
• Every record in a file should contain at least one field that
uniquely identifies that record, so that the record can be
retrieved, updated, and sorted. This identifier is called the
Primary Key. Eg: Passport Number

• Secondary key is another field that have some identifying


information, but typically do not identify the record with
complete accuracy. Eg: Last Name

24
Identify the Primary Key

25
Standard Methods of Organizing Data

26
File Management System

27
File Types

28
Drawbacks or Limitations of File
System
• Data redundancy or Data duplication
• Difficulty in accessing data (Query Inflexibility)
• Data integrity or inconsistency problems
• Lack of program-data independence
• Atomicity of updates not available
• Concurrent access by multiple users is not allowed
• Limited data security flexibility (Security at file level)

29
File Organisations

30
Advantages of Sequential Files

• They are simple to understand and use


• They are easy to organize and maintain
• They need relatively inexpensive I/O media and devices for
their storage and processing

Disadvantages of Sequential Files


• They are inefficient and uneconomical to use for application
in which activity ratio is low.
• Sequential processing requires extra overhead of sorting the
files before using them for processing

31
Advantages of Direct Files

• Given the key, any record can be quickly located and


retrieved directly
• It does not require transactions to be sorted in sequence
before processing

Disadvantages of Direct Files

• They require relatively expensive hardware and software


resources because they must be stored on a direct access
storage device, such as a hard disk.

32
Database Structure

33
Database
• A Database is an integrated collection of logically related
records or files consolidated into a common pool that
provides data for one or more multiple uses.
• Fields
• Hold an individual piece of data
• Are named descriptively
• Often called a column
• Phone book examples
• Name, address, e-mail, phone number
• Fields may contain no data
• Records
• One full set of fields
• Often called a row
• Phone book example
• Smith, Joe, 123 Some Street, 412-555-7777
• Databases may have unlimited rows 34
Types of Database

A database is a system intended to organize, store, and retrieve large


amounts of data easily. It consists of an organized collection of data for
one or more uses, typically in digital form. One way of classifying
databases involves the type of their contents, for example: bibliographic,
document-text, statistical. Digital databases are managed using database
management systems, which store database contents, allowing data
creation and maintenance, and search and other access.

35
Database Management System

(DBMS)
A Database Management System (DBMS) is a set of computer programs
or a software that controls the creation, maintenance, and the use of a
database.
 A DBMS is a system software package that helps the use of integrated
collection of data records and files known as databases. It allows
different user application programs to easily access the same database.

36
Advantages of DBMS
• Reduced data redundancy & inconsistency
• Application-data independence
• Improved security
• Improved strategic use of corporate data
• Reduced application development & maintenance cost

Features & Capabilities of DBMS


 Query Ability  Security, Granting privileges
 Backup & Replication  Computation
 Rule Enforcement  Change & Access Logging
 Automated Optimization 37
Data Model in DBMS
Data Model

Data models describe the structure of a database.


Data models are either conceptual data model or
physical data model.

The conceptual data model can have two


important categories
• Object-based Logical Model
• Record-based Model
Data Model in DBMS
Object-based Logical Model 

This model describes data at the conceptual and view levels. There are
several categories of this.

• Entity-relationship (E-R) model


• Object-Oriented model
Entity-relationship (E-R) Model 

The Entity-relationship (E-R) model consist


of a collection of basic objects and
relationship among these objects.

A distinguishable object that exists is called as an


entity. Each entity has associated with a set of
attributes associated with it. A relationship is
an association among several entities. The set
of all entities or relationships of the same type
is called the entity-set or relationship set.
Object-Oriented Model 

The Object-Oriented model is based on a


collection of objects, like the E-R model.
An object contains values stored in
instance variables within the object. The
values are themselves objects.
Thus objects contain objects to an arbitrarily
deep level of nesting. An object also contains
bodies of code that operate on the object.
These bodies of code are called methods.
Record-Based Logical Model 

The Record-Based Logical models


describes data at the conceptual and view
levels. Unlike object-oriented models,
these models specify overall logical
structure of the database, and provide a
higher-level description of the
implementation.

However, the three most-widely accepted record-


based models are :
• Network Model
• Hierarchical Model
• Relational Model
Network Model 

The Network data model represents data in network


structures of record types and the edges can be thought of
as one-to-one or one-to-many relationships.
There are just two fundamental data structures in the
network model. These are record types and set. The record
types are defined as collections of logically related data
items. A set expresses a one-to-many relationships between
two record types.

The DDL of a network model DBMS has three components


• A Schema section
• Record sections
• Set sections
The DML on the other hand, contains navigational
command to navigate through the network record
types, retrieval commands and update commands.
Network Database Model
• The network database model is a database model conceived as a flexible
way of representing objects and their relationships.
• In network database model, a child element can have more than one parent
element or no parent element at all.

44
Advantages

• Many more relationships can be defined


• There is greater speed and efficiency than with relational
database model

Disadvantages
 It is the most complicated model to design, implement and
maintain

45
Hierarchical Model 

Hierarchical data model are based on records which must


be related to each other in a hierarchy of many-to-one
relationships. On the conceptual level, the hierarchical
model is simply a special case of the network data model.
Rather than representing the data items in the form of a
network, hierarchical model represents the database as
hierarchy. If the network is visualized as a directed graph
the hierarchy is viewed as a tree.

There are two basic concepts associated with the


hierarchical model
• Segmented types
• Parent-child relation types
The main problem with the hierarchical database is that
inevitably you will require some records to be
associated with two other records on the ‘one’ side.
Hierarchical Database Model
• A hierarchical database model is a data model in which the data is
organized into a inverted tree-like structure.
• The structure allows repeating information using parent/child relationships:
each parent can have many children but each child only has one parent.

47
Advantages

• Adding and deleting records is easy


• Searching is fast and efficient

Disadvantages

 Navigational and procedural nature of processing


 Limited search/query flexibility
 Not all the data are naturally hierarchical

48
Relational Model 

Relational databases are widely used at present and their


use will continue to grow in the future. They do not
presuppose any rigid structure on the data and use the
familiar notions of records and files.

Their popularity as an alternative to non-relational databases


can be described to the following two reasons
• The non-relational databases impose a rigid structure on data in the
form of owner-member relationships that new users find difficult to
understand
• To formulate a query in a non-relational database, users have to
navigate through the schema and use a procedural language
Relational Database Model
• The relational database model is based on the simple concept of tables in
order to capitalize on characteristics of rows and columns of data.
• This database model based was first formulated and proposed in 1969
by E.F. Codd

50
Advantages

• There is no predefined relationship among data


• High flexibility in search or query
• New data and records can be added easily

Disadvantages
 Processing efficiency and speed are lower
 It requires additional maintenance effort.

51
Object-Oriented Database Model
• Object oriented database model (OODM)was introduced to overcome the
shortcomings of conventional database models.
• OODM is a collection of real world objects whose behavior, state, and
relationship can defined in accordance with object oriented concepts.
ta &
s
ge
an e s
d v ag
sa n t
D i va
Ad

52
Database Architecture
• Centralized Database Architecture
• A Centralized database has all the related files in one physical location.
• Centralized database save the expenses associated with multiple mainframe
computers, but also provide database administrators with the ability to work on
a database as a whole at one location.
• Files can generally be made more consistent with each other when kept in one
location, because file changes can be made in a supervised and orderly fashion.
• Centralized database is vulnerable to single point of failure.
• Access speed is often a problem when users are widely dispersed and must do
data manipulation from distances, causing transmission delays.
• Distributed Database Architecture
• A Distributed database has complete copies of database, or portion of database,
in more than one location, which is usually close to the user.

53
Centralized Distributed
Database Database
Architecture Architecture

54
Types of Distributed Database
Architecture
• Partitioned Distributed Database
• A partitioned database is subdivided, so that each location
has a portion of the entire database (usually the portion that
meets users’ local needs). Major problems are
telecommunication costs and time delays.
• Replicated Distributed Database
• A replicated database has complete copies of the entire
database in many locations, primarily to alleviate the single-
point-of-failure problems of a centralized database.
Advantages of the Both

55
Operational or Transactional
Database

• These databases store detailed data about the day to day operations
of an organization.
• They are typically organized by subject matter, process relatively high
volumes of updates using transactions.
• Examples include customer databases that record contact, credit, and
demographic information, personnel databases that hold information
such as salary, benefits, skills data about employees.

56
Continued..

• Data warehouses archive modern data from operational databases


and often from external sources such as market research firms.
• Often operational data undergoes transformation on its way into the
warehouse, getting summarized, categorized, reclassified, etc.
• The warehouse becomes the central source of data for use by
managers and other end-users who may not have access to
operational data. Some basic and essential components of data
warehousing include retrieving and analyzing data, transforming,
loading and managing data so as to make it available for further use.

57
External Database

• These databases contain data collected for use across


multiple organizations, either freely or via subscription. The
Internet Movie Database (www.imbd.com) is one example.

Hypermedia Database
 The World wide web can be thought of as a database, albeit
one spread across millions of independent computing
systems. Web browsers "process" this data one page at a
time, while web crawlers and other software provide the
equivalent of database indexes to support search and other
activities. 58
Architecture of
DBMS
Data Abstraction

DBMS provides its users the facility to use the database, to


retrieve the relevant data from the database. Different users
retrieve only the relevant data as per their requirement and
DBMS represents information in a customized format.

Otherwise it is called as the presentation of information by


DBMS through a view or abstracted view where the data
stored in the database is independent from the representation
through the view, only it is used. This is called as Data
Abstraction or abstracted data presented to the user.
Architecture of
DBMS
Data Abstraction

Otherwise it is called as the presentation of


information by DBMS through a view or
abstracted view where the data stored in the
database is independent from the representation
through the view, only it is used. This is called as
Data Abstraction or abstracted data presented to
the user.
Architecture of
DBMS
Data Abstraction

This is a significant feature of DBMS, in which


each of the users views the same data at different
levels of abstractions. DBMS does in fact provide
such abstractions which eventually reflects on the
DBMS architecture.

There are three levels of data


abstraction:
Architecture of
DBMS

Internal / Physical Level 

This is the lowest level of abstraction, which is concerned


with the physical storage allocation, access specification
paths & mechanisms, keys, index & pointers and
sequencing, data compression & encryption techniques and
optimization of the internal structure organization etc.
Architecture of
DBMS

Conceptual Level 

This view is the information model of the enterprise


and contains the view of the whole enterprise without
any concern for the physical implementation. It is a
representation of the entire information content of
the entire database, in a form that is some what
abstract in comparison with the way in which the
data is physically stored. The conceptual schema
hides the details of physical storage structures and
concentrates on describing entities, data types,
relationships, user operations and constraints.
Architecture of
DBMS

External / View Level 


• This is the highest level of abstraction, which
describes only a part of the entire database that
concerns a particular end user. It is often a
restricted view of the database and the same
database may provide a number of different
views for different classes of users. Each of these
describes the part of the database that a
particular user group is interested in and hides
the rest of the database from that group of users.
• There can be many level of abstractions of the
same data, where as there only one conceptual
level of abstraction.
DBMS Architecture

The conceptual framework, three level


architecture of DBMS is based upon the three
level data abstraction mechanism which
allows a clear separation information
meaning (conceptual view) from the external
data representation and from the physical
data structure layout. A database system that
is able to separate the three different views
of data is likely to be flexible and adaptable.
This flexibility and adaptability is otherwise
called as data independence.
DBMS Architecture

• External Schema – Each external view is


defined by means of an external schema,
which consists basically of definitions of
each of the various types of external
record found in that external view.
• Conceptual Schema – The conceptual view
is defined by the conceptual schema which
includes definitions of each of the various
types of data or the various types of
conceptual record.
DBMS Architecture

• Internal Schema – The internal view is defined by


means of an internal schema, which not only
defines the various types of record but also
specifies what indexes exist, how stored fields
are represented, what physical sequence the
stored record are in etc. the internal schema
uses a physical data model and describes the
complete details of data storage and access
paths for the database. It dictates the internal
structure of the stored records. However it does
not deal with any device-specific considerations
such as cylinder or track sizes.
DBMS Architecture
Data Independence

Data independence is a major


objective of database systems. It is
implemented through the three
levels of architecture such that
change at one level does not affect
the application or definition at the
other level.
DBMS Architecture
Data Independence

• Physical Data Independence – Physical data


independence is the ability to modify the
internal schema without causing any
change the external schema and causing
application programs to be re-written.
• Logical Data Independence – Logical data
independence is the ability to modify the
logical conceptual schema without causing
application programs to be re-written or
any change to external schema..
Logical independence is harder to achieve.
DBMS Architecture
System Architecture

System architecture in DBMS is used to


identify the different functional units of a
DBMS and as well as used to define their
mode of functioning.
DBMS provide the facilities like
• Describing the database, when a database is
being setup
• Authorization specification and checking
• Access path selection
• Concurrency control
• Logging and recovery
DBMS Architecture
The main components of the DBMS are:

 A Query Language and a DDL to


provide the users the access to the
database
 A translator for users’ instructions in
the query language and the DDL
including query optimization
 A Database manager
 A file manager
 The physical database
 The metadata (The information (data)
about the data in a database)
Application DBA
User
Programmer

Query Language

DDL
Compiled
Query
Object
Optimization
Code

Database Manager

File Manager

Physical Metadata
Database

DBMS System Architecture


Database or DBMS Architecture
• Database architecture
consists of three levels:
• External or View Level
• Conceptual Level
• Internal or Physical Level

73
74
Continued...

• The external level defines how users understand the organization of


the data. A single database can have any number of views at the
external level.
• The internal level defines how the data is physically stored and
processed by the computing system. Internal architecture is
concerned with cost, performance, scalability and other operational
matters.
• The conceptual is a level of indirection between internal and external.
It provides a common view of the database that is uncomplicated by
details of how the data is stored or managed, and that can unify the
various external views into a coherent whole.

75
Database System : Concept &
Architecture
Database languages
In order to provide the various facilities of DBMS to
different types of users, DBMS provides one or more
specialized programming languages called as Database
Languages. However, a language called Structured Query
Language (SQL) has recently been taken as the standard
database language.
A language is needed to describe the database to the DBMS
as well as provide facilities for changing the database and
for defining and for changing physical data structures.
Database System : Concept &
Architecture
Database languages
Another language is needed for manipulating and retrieving data stored in
DBMS.

These languages are called


Data description languages (DDL)
Data Manipulation Languages (DML)
respectively.
Database System : Concept &
Architecture
Data Description Languages (DDL)
It is used to describe the details of the data. DBMS will have
a compiler whose function is to process DDL statements in
order to identify & store the descriptions (Conceptual
Schema) as a set of tables in the Data Dictionary. Thus Data
Dictionary is a file which contains the data about the data or
Metadata.

Another language, the Storage Definition language (SDL) is


used to specify the Internal Schema. The mapping between
the two languages can be specified by any one of the
languages.
Database System : Concept &
Architecture
Data Manipulation Languages (DML)
Once the database schemas are compiled and the database
is populated with data, users must have some means for
manipulating the database.

By data manipulation, we mean the following.


• The retrieval of information stored in the database
• The insertion of new information into the database
• The deletion of information from the database
• The modification of information stored in the database
Database System : Concept &
Architecture
Data Manipulation Languages (DML)
The language that enables users to access or manipulate
data is called the DML.

DML are of following two types.


• Procedural DML which require users to specify what data
are needed and how to get those data
• Nonprocedural DML which require a user to specify what
data are needed without specifying how to get it.
Database System : Concept &
Architecture
Each DBMS has a DDL as well as a DML. The two languages
together may be part of the Unified database language.

The Languages come in the following two forms.


• Extended Host languages These are subroutine calls from
one or more programming languages. The programming
language that is extended is usually called the Host
Language.
Language
• Query Languages These are special purpose languages that
usually provide more powerful facilities to interact with the
database. These languages are often designed to be simple
so that non-programmers may se them.
Main Components of DBMS

82
Data Definition Language (DDL)
• A Data Definition Language (DDL) is a computer language for defining data
structures. DDL include three statements.

1. Create Statements
CREATE TABLE employees ( id INTEGER PRIMARY KEY, firstname CHAR(50)
NULL, lastname CHAR(75) NOT NULL, dateofbirth DATE NULL );

2. Drop Statements
Drop - To destroy an existing database, table, index, or view.
Example: DROP TABLE employees;

3. Alter Statements
Alter - To modify an existing database object.
Example: ALTER TABLE sink DROP COLUMN bubbles;

83
Data Manipulation Language (DML)
• Data Manipulation Language (DML) is a family of computer languages used
by computer programs and/or database users to insert, delete and update
data in a database.
DML include the following statements:
• Insert
INSERT INTO table_name (FieldName1, FieldName2) Values (Value1, Value2);
• Update
UPDATE table_name
SET column1=value1, column2=value2,
WHERE some_column=some_value
• Delete
DELETE FROM table_name [WHERE Clause]

84
Query Language

• Query languages are computer languages used to make


queries into databases.
• Query Language includes the following statement:
1. Select
The purely read-only SELECT query statement is classed
under query language.
Ex:- Select * from Table_name where city = “London”.

85
Database System : Concept &
Architecture
Database Administrator (DBA)
The Database Administrator is a person having central control over data and the
programs accessing the data.

The Responsibilities of a DBA.


• Authorizing access to the Database
• Coordinating & Monitoring its use
• Acquiring S/w & H/w resources as needed
Database System : Concept &
Architecture
The Tasks of Database Administrator (DBA)
The Database Administrator has to carry out certain important tasks.

The Tasks of a DBA.


• Deciding & Loading the Database Contents
• Assisting & Approving Applications & Access
• Deciding Data Structures
• Backup & Recovery
• Monitor Actual Usage
The other duties of a DBA
• Defining security & integrity checks
• Monitoring performance & responding to changing requirements
• Liaising with users
Database System : Concept &
Architecture
Database Designers

The Database Designers are Responsible for


• Identifying the data to be stored in the Database
• Choosing appropriate structures to represent and store the
data
The Responsibilities of Database Designers are
• Schema Definition
• Storage Structure & Access Method Definition
• Schema & Physical organization modification
Database System : Concept &
Architecture
Database Users

Other than DBA & Database Designers, who mostly uses the Database
• Application Programmers
• End-users
The various types of end-users are are
• Sophisticated end-users
• Specialized end-users
• Naive end-users
• System Analysts
Dealing with various Front-end & Back-end applications with the
database, where DBMS itself acts as the backend application tool
Database System : Concept &
Architecture
Database Manager

The Database Manager is not an individual but a program


module which provides the interface between the low-level
data stored in the database and the application programs
and queries submitted to the system.
The Database Manager module is responsible for all the
following tasks
• Interaction with the file manager
• Integrity Enforcement
• Security Enforcement
• Backup and Recovery
Database Administrator
• A database administrator (DBA) is a person responsible for managing the
database system, authorizing access, coordinating & monitoring uses,
acquiring resources.
• They are also known by the titles Database Coordinator or Database
Programmer.

Role of the DBA


 Installation of new software.
 Configuration of hardware and software with the system administrator.
 Security administration.
 Data analysis.
 Database design (preliminary).
91
Database Designer
• A database designer is responsible for designing the database,
identifying the data to be stored, choosing the structure to represent
and store this data.

End Users
 End Users are the persons who use the database for querying,
updating, generating reports etc.

 Casual end users: Occasional user such as middle-level or high-level


managers
 Parametric end users: Users who are continuously interacting with
the database. Eg. Bank tellers
 Sophisticated end users: Use full DBMS capabilities for
implementing complex applications. 92
ER Diagram Student’s ER Diagram

93
Entity-Relationship
Model

Entity-Relationship (ER) model is a popular


tool for high-level conceptual database
design. To consider the different stages of
building a database application, the first
step is likely to analyze the scope of the
system. This step of designing a database
application is called as the requirement
analysis. This is usually an informal process
that involves discussion with the user-group
and the study of the existing process.
Entity-Relationship
Model

The next step is to develop a high-level


description of the data based on the information
gathered in the requirement analysis. This step
is called as conceptual database design. It is a
concise description of the data requirements of
he users and includes detailed descriptions of
the data types, relationships, and constraints.
This stage does not include any implementation
details. The descriptions are easier to
understand and can be used to communicate
with the non-technical persons.
Entity-Relationship
Model

The third step is called logical database


design. In this step we map the details of
conceptual design to a DBMS
environment. The high level description of
the second step is converted to a form
that can be directly implemented with the
help of a DBMS.
The next step is physical database design
where the actual implementation of the
design takes place.
Entity-Relationship
Model

Entity-Relationship (ER) model is a mechanism


based on which database systems can be built by
considering data as entities, relationships and
attributes. The atomic object, on which the ER
model is built, is an entity, which has an
independent existence. Each entity is described
by a set of properties called attributes. Entities
are related among themselves by different
relationships. Similar entities are part of an
entity-set and in similar way relationship sets are
defined for similar relationships, which are the
basic constructs of the E-R modelling.
Entities, Attributes &
Relations

Entity-Relationship (ER) model is a mechanism


based on which database systems can be built by
considering data as entities, relationships and
attributes. The atomic object, on which the ER
model is built, is an entity, which has an
independent existence. Each entity is described
by a set of properties called attributes. Entities
are related among themselves by different
relationships. Similar entities are part of an
entity-set and in similar way relationship sets are
defined for similar relationships, which are the
basic constructs of the E-R modelling.
Entities and
Relations
Entities and Entity Sets
Entities

• An entity is an object that exists and is distinguishable form other objects


• An entity is a thing in the real world with an independent existence
• Entity is an object in real world that has certain properties
Entities and
Relations
Entities and Entity Sets

Thus, an entity can be concrete (like a person, a


book etc.) or abstract (like holiday, a day, a class
etc.)

The different entities may be sharing all or some


common properties

Entity Category Properties


Entities and
Relations
Entities and Entity Sets

Entity Type

• A database usually contains group of entities that are similar.


• Entity type is an abstraction, defining the properties (attributes) of a
similar set of entities.
Entities and
Relations
Entities and Entity Sets

Entity Instances

• Entity instances are instantiation of entity types


For Ex. - entity type ‘student’ are Mr. X & Y. both x & y shares some common property.
• Thus, entity can be instances of many different entity types.
For Ex.- Student & Customer.
Entities and
Relations
Entities and Entity Sets

Entity Set

• An entity set is a set of entity instances that are of the same type.
Ex.- SBI account holders and MBA students are different entity types,
but some student are also account holders.
• That’s why entity sets need not be disjoint.
Attributes and
Relations
Attributes

• Entities have certain properties called as attributes. An entity is in fact described


or, represented by a set of attributes.
Ex.- Name, Roll No, Semester etc. of a Student.
• We can identify an entity from the specified values of its attributes.
Each attribute has a domain for which the values for this attribute are drawn
Attributes and
Relations
Types of Attributes

Single and Multi-valued Attributes

• In practice most attributes have a single value for a particular entity.


Name, Roll No etc. are single value attributes for a student.
• Attributes having more than one value are multi-valued attributes
(White, Red, Green, Blue and Black) are the colour of a paper. Then
Lower Bound is ‘White’ and Upper Bound is ‘Black’.
Attributes and
Relations
Types of Attributes

Simple and Composite Attributes

• The attributes that are not divisible are called as simple or atomic attributes.
• Composite attributes can be divided into smaller sub parts.
Ex.- Address of a student an be subdivided into Plot No, Street, Area and Pin etc.
Attributes and
Relations
Types of Attributes

Stored and Derived Attributes

A attribute can be a stored or a derived attribute.

DOB and Age


Mark (1 - M) and Result
Attributes and
Relations
Types of Attributes

Null Values

In the address of a student if Pin No is not available there. For such situation, a special value
called Null Value is created.

The other situation when null values are used when the attribute is not applicable.
Relations in E-R
Model
Relationship

Once the Entities and Attributes are outlined, then relationship describes
how they are related to one another. Relationship is an association between
several entities. Formally, it is a mathematical relation on n(≥2, possibly
non-distinct) entity sets. If E1, E2, …, En are entity sets then a relationship R
is a subset of
{(e1, e2, …., en) | e1 E1, e2 E2, …., en En}
We can have more than one relationship that are defined over the
same sets E1, E2, …., En. Each elements of the sub set is an instance
of the corresponding relationship.
A collection of the relationship instances of the same type is called a
relationship set.
Relations in E-R
Model
Relationship

S1  t1
s1 
S2 
s2 
S3  t2
s3 




 

Relationships (Binary)
Relations in E-R
Model
Relationship
T1 
S1  T2 
S2  T3 
S3 

S  Subject
T  Teacher
Y  Year

The degree of a relationship type is the number of participating entity types.


Y1 
Y2  Ternary
Y3  Relationship
Relations in E-R
Model
Relationship
Cardinality Constraint

The relationships of degree 2 are also called binary


relationships. Thus in a binary relation type, two entity sets
participate. But there can be different modes of
participation of entity instances in the relationship instances
of a binary relation type. Based on the participations of
entity instances, the binary relation types are categorized
as-
• One-to-One
• One-to-Many
• Many-to-Many
• Many-to-Many
Relations in E-R
Model
Relationship

Participation

• Each entity type that participates in a relationship type plays particular role in
the relationship. The role name signifies the role that a participating entity plays
in each relationship instance.
• When the participating entity types are not distinct in the relationship
types, they are called recursive relationships.
Relations in E-R
Model
Relationship

Participation Constraint

The participation constraint specifies whether occurrence of an entity


depends on it’s being related to another entity in a relationship.
This constirant is of two types-
Total
Partial
If an entity E1 is in total participation in relationship R, then every instantiation of entity in E1,
say e1, must participate via relationship set R to an entity instance R2 in E2.
Thus, any participation that is not total is said to be partial participation.
Relations in E-R
Model
Relationship

Attributes of Relationship

Relationship types can also have attributes, similar to those of entity


types.

Ex.- To record the number of hours of lecturers per week can be


attribute of relationship TEACHES.
Role of Keys in E-R
Model
Key

An entity type usually has some attributes whose


values are distinct for each individual entity.

A super key is a set of one or more attributes which taken


collectively, allows us to identify uniquely an entity in the entity
set.

A super key for which no subset is a super key is called a


candidate key.
Ex.- Roll Number is a candidate key as it is a minimal super key.
Role of Keys in E-R
Model
Key
A primary key is a candidate key (there
may be more than one) chosen by the
database designer to identify entities in an
entity set. The primary key is used as the
primary access mechanism for the entity
set.

A composite key is a candidate key with two or more


attributes.
Role of Keys in E-R
Model
Key

An entity set that doesn’t possess sufficient


attributes to form a primary key is called weak entity
set. One that does have a primary key is called a
strong entity set. For a weak entity set to be
meaningful, it must be part of a one-to-many
relationship set with strong entity set. This is a case of
obligatory membership.
Role of Keys in E-R
Model
Key

The strong entity types can exist of their own, without


participating in any relationship. But it is not so with
weak entities. Each instance has to participate in a
relationship with a strong entity set in order to exist.
This strong entity set is called owner of the weak
entity set.
Role of Keys in E-R
Model
Key

A weak entity set does not have a primary key but we


often need a means of distinguishing the entities. The
discriminator of a weak entity set of attributes that
allows this distinction to be made. The primary key of
the (owner) strong entity set on which its existence
depends plus its discriminator uniquely identifies each
instance of weak entity.
Entity Relationship (ER) Model

• E-R Model is an abstract and conceptual representation of


data that is used in the design of a database application.
• Three building blocks of E-R Model
• Entity
• Relationship
• Attributes

121
Entity

• 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 may be a physical object such as a house or a car, an event
such as a house sale or a car service, or a concept such as a customer
transaction or order.
• Ex: Employee, Bike, Laptop, Student, House etc

Employee Student

122
Entity Set

• It is a set of entities of the same type that share the same properties.
• Ex: Set of all the students, employees etc.

123
Relationship

• A relationship captures or defines how two or more entities


are related to one another.
• Examples: an owns relationship between a supervises
relationship between an employee and a department, a
performs relationship between an artist and a song.

owns performs

124
Attribute

• Entities and relationships can both have attributes. These


are characteristics or properties associated with a particular
entity.
• Examples: an employee entity might have a Passport
Number, Driver’s License as attribute; the proved
relationship may have a date attribute.

Passport Driver’s
Number License
Number

125
Notation for E-R Diagrams

• Rectangles represent entity sets.


• Diamonds represent relationship sets.
• Lines link attributes to entity sets and entity sets to relationship sets.
• Underline indicates primary key attributes
• Task: Customer borrows loan from a bank.

126
Solution

127
• Ellipses represent attributes
• Double ellipses represent multi-valued attributes.
• Dashed ellipses denote derived attributes.
• Composite Attributes
128
Relationship Set with Attributes

129
Types of Relationships

• One-to-One
• One-to-Many
• Many-to-Many

130
One-to-One Relationship

In one-to-one relationship, a loan is associated with only one customer.

131
One-to-Many Relationship

In the one-to-many relationship, a loan is associated


with at most one customer via borrower, a customer is
associated with several loans via borrower

132
Many-to-Many Relationship

A customer is associated with several possible loans via borrower,


a loan is associated with several customers via borrower

133
E-R Diagram with a Ternary
Relationship

134
Structured Query Language
Structured Query Language (SQL)

• SQL is a database computer language designed for managing


data in relational database management systems (RDBMS),
and originally based upon relational algebra and calculus.
• Its scope includes data insert, query, update and delete,
schema creation and modification, and data access control.

136
Data Types

• Character strings
• CHARACTER(n) or CHAR(n) — fixed-width n-character string, padded
with spaces as needed
• CHARACTER VARYING(n) or VARCHAR(n) — variable-width string with a
maximum size of n characters
• NATIONAL CHARACTER(n) or NCHAR(n) — fixed width string supporting
an international character set
• NATIONAL CHARACTER VARYING(n) or NVARCHAR(n) — variable-width
NCHAR string

137
Continued…

• Numbers
• INTEGER and SMALLINT
• FLOAT, REAL and DOUBLE PRECISION
• NUMERIC(precision, scale) or DECIMAL(precision, scale)

138
Continued..

• Date and time


• DATE — for date values (e.g., 2010-05-30)
• TIME — for time values (e.g., 14:55:37). The granularity of the time
value is usually a tick (100 nanoseconds).
• TIME WITH TIME ZONE or TIMESTAMP — the same as TIME, but
including details about the time zone in question.
• TIMESTAMP — This is a DATE and a TIME put together in one variable
(e.g., 2010-05-30 14:55:37).
• TIMESTAMP WITH TIME ZONE or TIMESTAMPTZ — the same as
TIMESTAMP, but including details about the time zone in question.

139
Select Statement

Employee Table

Emp_Id Name City State Phone

512687458 Joe Atlanta Alabama 534-678-3425

758420012 Mary Howard Ohio 342-876-6732

765125638 Sarah Phoenix Arizona 932-245-8213

SELECT Name, City, State FROM Employee Table;

140
Solution

Employee Table

Name City State


Joe Atlanta Alabama
Mary Howard Ohio
Sarah Phoenix Arizona

To get all columns of a table without typing all


column names, use:
SELECT * FROM Employee Table;

141
Relational Operators

• There are 6 relational operators in SQL

Relational Operators
= Equal
!= Not Equal
< Less Than
> Greater Than
<= Less Than Equal To
>= Greater Than Equal To

142
Conditional Select

Salary Table
Emp_Id Name Salary Position
010 Sibanjan 50000 Manager
045 Swagat 55000 Manager
022 Rakesh 30000 Clerk
025 Shivani 25000 Executive
055 Jyoti 60000 CEO

Select * from Salary Table where Salary = > 50000;


Select Emp_Id, Name from Salary Table where Position = ‘Manager’ and Salary > 50000;
Select * from Salary Table where Salary Between 20000 and 30000;

143
Aggregate Functions

• SUM () gives the total of all the rows, satisfying any


conditions, of the given column, where the given
• column is numeric.
• AVG () gives the average of the given column.
• MAX () gives the largest figure in the given column.
• MIN () gives the smallest figure in the given column.
• COUNT(*) gives the number of rows satisfying the
conditions.

144
Example
Salary Table
Emp_Id Name Salary Position
010 Sibanjan 50000 Manager
045 Swagat 55000 Manager
022 Rakesh 25000 Clerk
025 Shivani 30000 Executive
055 Jyoti 60000 CEO

• Select Sum (Salary), Avg (Salary) from Salary Table;


• Select Min (Salary) from Salary Table where Position = ‘Manager’;

145
Applications of SQL
• Creating New Table
• CREATE TABLE ORDERS (OWNERID INTEGER NOT NULL PRIMARY KEY,
ITEMDESIRED CHAR(40) NOT NULL, ORDERDESC VARCHAR(50) NOT NULL,
DATE_OF_ORDER DATE );
• Altering Table
• ALTER TABLE ANTIQUES ADD (PRICE DECIMAL(8,2) NULL);
• Inserting Data into Table
• INSERT INTO ANTIQUES VALUES (21, 01, 'Ottoman', 200.00);
• Deleting Data from Table
• DELETE FROM ANTIQUES WHERE ITEM = 'Ottoman';
• Updating Data
• UPDATE ANTIQUES SET PRICE = 500.00 WHERE ITEM = 'Chair';

146

You might also like