You are on page 1of 49

Database Management System

DBMS

1
Data and Information

• Data is the collection of raw


findings, facts, measurements.
• It does not have meaning.
• After processing the data, we
get information.
2
• For example: 5.4, 5.6 and 5.8
have no meanings. But Table 1
is information which has
meaning.

SN Name Height
1 Rubina 5.4
2 Rabin 5.6
3 Raoul 5.8
3
• A collection of information
is stored in computer as a file.

• A record is the collection of


interrelated fields.

• A field is the property or


attributes of a table.
Ex: SN, Name, weight are fields
4
DBMS and DB
• DBMS is basically a Computerized records keeping
system.
• It is a special type of software to manage large collection
of data.
• DBMS is defined as the collection of interrelated data
and set of programs to access those data.
• A collection of interrelated data is termed as database
which is very useful information of an organization for
decision making.
• A set of programs is special database query language
for accessing the database
• Popular database packages are: FoxPro, Sybase, Dbase,
MS ACESS, MY SQL, MS SQL Server, DB2, Oracle
5
User1

User2 Request DBMS D


B
User3

Database Request
• Adding new file to the DB
• Inserting data into the DB file
• Retrieving/Viewing data from DB
• Updating data in DB database file
• Deleting data from the DB file
• Removing files from the DB
6
Advantages of DBMS
1. Data Integrity
2. Data security
3. Data Redundancy
4. Data Independence
5. Backup and Recovery
6. Multiple Access
7. Process Complex query
8. Provides Interface: Form, Report
7
Database Administrator (DBA)
Who?
• The most responsible person with
sound knowledge of DBMS and IT.
• Administrator of the system.
• Has the maximum amount of privileges.
• Keep the database server up-to-date
secure
• Provides information to users on
demand.
8
Qualities?
• Sound knowledge of database:
Database Design, SQL (Structured
Query Language) and database
report.
• Strong knowledge about computer
system, OS, networking,
• Knowledge of modern database
packages: MS-Access, MS SQL-
Server, My SQL, Sybase Oracle etc.
9
Role ?
• Responsible for database design
i.e. designing all tables, fields,
Forms, Report, relationship and
users’ privileges.
• Provides different interface for
data retrieving and entering.
• Creates user manuals, give
training, describing the facilities of
by the system
10
• Maintains database security,
backup strategy, integrity
constraints and documentation of
data dictionary.
• Supervises the addition,
modification and deletion data
from the database.

11
Database Model
• An approach to manage data in
database is called database model.
• Defines organizing principle of
database that gives the mechanism
for data access and store.
• most common database models
• Hierarchical Model
• Network Model
• Relational Model
• ER Model 12
Flat File system/File Processing
• Traditional way of storing data
electronically (before DBMS)
• Stores data in a single stream of bytes
(In One Binary File)
• Has number. of limitations. It does not
support data integrity, Security,
Relationship, etc.
• Difficult for complex request (query) to
the database. 13
Hierarchical Model
• The oldest type database models.
• Data is represented in the form of records.
• Each record has multiple fields/attributes.
• All record is arranged in database as tree
like structure.
• The relationship between the records is
called parent child relationship in which
any child record relates to only a single
parent type record.
14
Records
(Principal)

Records Records Records


(students) (management) (Department Chief)

Exam Personal Employee Teacher Employee


records records records record records

Fig: Hierarchical Database Model


15
Network Model
• It replaced hierarchical model due to some
limitation
• It arranges non- hierarchical database.
• The structure is more like graph rather
than tree structure.
• It consists of collection of records that are
inter-related to each other with the help of
relationship.
• Each record has multiple fields and each
field has only one data value.
16
Records
(Principal)

Records Records Records


(students) (management) (Department Chief)

Exam Personal Employee Teacher Employee


records records records record records

Exam
records

Fig: Network Database Model


17
Relational Model (RDBMS)

• RDBMS is the modern database approach


• It uses a collection of tables to store data.
• Each table has unique name with equal
number of rows and columns.
• A column defines the data field and a row
defines a record in a table.
• Each data field must have atomic data
value.
18
• Relationship is the association
between two tables and it is
represented by the common fields of
both the tables.
• There are three types of relationship
in relational model:
• one to one
• one to many
• many to many

19
Customer_detail
fname Lname Street Acc_no
Abee Gurung Ratopool A001
Rita Shrestha Lagankhel A002
Ani Lama Jawalakhel A003

Account_detail
Acc_no Balance
A001 54000
A002 38005
A003 97005

Customer_detail
Account_detail
fname
Acc_no
Lname
balance
Street
20
Acc_no
Relationship
(Functional Cardinality)
• Relationship is the link between two more
tables.
• It shows the dependency between the tables
for building queries and make database
easy access.
• There are three types of relationship:
• One-to-one: Each record in table A must
have only one matching record in the other
table B and each record in table B must have
one matching record in table A.

21
College has Principal

Colleges Principal
GLOBAL MR ABC
UNIVERSAL MR XYZ
CAMPION Ms PQR

• One-to-many: Each record in table A can


have multiple matching records in table B
and each record in table B can have only
one matching record in table A.

22
Department work Faculty
s

Department Faculty
COMPUTER MR HIM Sir
ECO MR Devendra
Sir
English MR Kumar Sir
MR Pradeep Sir

Many-to-many: Each record in table A can have


multiple matching records in table B and each
record in table B can have multiple matching
records in table A. It exists only by defining a third
table which consists of common fields or keys
23
Book writes
Author

BN BOOK NAME AN BOOK AUTHOR


B1 DBMS A1 Dr. AA
B2 C Language A2 Dr. SINGH
B3 HTML
BN AN
B1 A1
B1 A2
B2 A1
B3 A1
B3 A2
24
E R Model/Diagram
• E-R diagram is the most commonly
used database designing tool.
• It shows overall logical structure of a
database graphically.
• Entity, attributes and relationship are
the components of E-R diagram.

25
• Entity: It is the thing or object in the real world that
cab be distinguishable from the others.
Example: student, employee, bank_account etc.
• A collection of same entities is called entity set.
• It is expressed by rectangle.
• Attributes: An entity is described by a set of
properties called attributes.
For example s_id, roll, f_name, l_name, section,
etc are the attributes of an entity student.
• It is expressed by oval shape.
• Relationship: It is an association or dependency
between two entities.
• A collection of same relationships is called
relationship set.
• There are three types of relationship: one-to-one,
one-to-many and many-to-many.
• It is expressed by diamond shape.
26
Rectangle Entity or entity set
Ellipse
Attributes
R Relationship between entity sets
Links between the entity sets

roll f_na
co m

sid
me eco
sid

1 1
Student_detail R Exam_detail

l_na c al
me se acc tot
math
phon
e

27
Structured Query Language
• It is an international standard database query
language.
• It is adapted by many computer and
software manufacturers such as IBM,
Microsoft, Oracle, Sybase etc.
• It was developed in IBM's laboratory in 1970s.
• It was originally called sequel, after that
its name was changed into SQL.
• SQL is not a complete programming
languages.
• It is only used for communicating with BD.
• It defines both DDL and DML.
28
Data Definition Language
• It is used in order to define or specify the
logical structure of database. A few DDL
commands are:
– Create table
– Add/modify fields
– Delete table

29
Data Manipulation Language
• It is used in order to manipulate or access
data in database. A few DML commands
are
– Insert data value
– Select or view records
– Update records
– Delete records

30
Domain and tuple

• Domain is the range of value for


the given field of a table.
For example age of a person is
in-between 0-100.
• A record in a table is called tuple

31
Data Dictionary
• It is a file that contains meta-data i.e. data
about data.
• It is also called information system catalogue.
• It keeps all the information about the DB
system such as location, size of the database,
tables, records, fields, user information,
privileges, backup system, and recovery
system etc.
• It also defines the data types for each fields
etc.
• A good data dictionary always ensures the
consistency in data base.
32
Table, Schema and Instance
• A table contains a logical grouping inter related
data where the data is arranged in equal number of
rows and columns.
• Each column defines the fields or attributes of a
table.
• Each row in a table defines a record or tuple.
• A schema is the structure of a table i.e. it defines
attributes of an entity and domain of the attributes.
• Instance is interrelates data values in a record
• Schema for a table: a book
Book (bId, bName, price, no_copy, bAuthor)
• Instance for the table: book
A001 A Book On C 545 10 Paul & Kelly

33
Key
• Candidate Key: A Candidate key is the minimum
number of field or fields in a table that uniquely
determines a record in a table.
• Primary Key: A unique key can be designated as
primary key if it has a unique identification for each
record of a table.
• Any candidate key can be considered as the primary
key.
BOOK (bId, bName, price, no_copy, bAuthor)
Foreign Key: A field in the related table that the
primary key refers to is called foreign key.
• STUDENT( s_id, f_name, L_name, grade, sec, roll)
• EXAM( s_id, sub1, sub2, sub3, sub4, sub5, total)

34
Functional Dependency
• If a value of any field or attribute uniquely
determines the value for the other fields or
attributes, then the attributes are functionally
depends on the common field.
• In table: student, sid is the primary key which
uniquely determines all the data values for the
other attributes. So fname, lname, city, street,
mobile fields are functionally dependent on sid.

Student_table
sid Fname Lname City Street mobile

35
Normalization
• It is a database design process in which
complex database table is broken down
into simple separate tables.
• It minimizes and controls the duplication
of data in a database and also provides a
rapid search for data from the database.
• It reduces the complexity of database.
• It is a complex process with many rules
in many layers.

36
• There are five levels of normalization
process as shown in fig 1.
1NF
2NF
3NF
4NF
5NF

Fig 1: Normal Form


The relation first check for 1NF, if not, convert it into 1NF. Similarly
the relations are checked for 2NF, 3NF, 4NF and 5NF. 37
Normalization Process

• The main objectives of normalization


process are as follows:
– Dependency between the data fields is
identified.
– Redundancy in database is minimizing.
– Data model is made more flexible and
easier to maintain.

38
Let us consider the following example:
LIBRARY( member_id,
member_name,
book_code,
book_name,
issue_date,
return_date)

member_id member_name book_code book_name issue_date return_date


R01 Rabi 5002 DBMS 15/01/2006 25/01/2006
A02 Abi 5005 C Program 17/01/2006 24/01/2006
R01 Rabi 5007 Network 25/01/2006 NULL
A02 Abi 5002 DBMS 27/01/2006 NULL

39
1NF ( First Normal Form)
• Definition: A table is in 1NF if, there are
no duplicate rows or columns in the table
and each data value in a field must be
atomic (single value) and same type.
• In above example member_name field is
not atomic, so it is divided into
member_fname & member_lname.
LIBRARY (member_id, member_fname,
member_lname, book_code, book_name,
issue_date, issue_return)
40
2NF (Second Normal Form)

• A table or relation is in 2NF if it is in 1NF


and non key attributes are fully dependent
on primary key not just a part of it.
• The main job of 2NF is to eliminate partial
key dependency.
• In order to decompose in 2NF, we have to
identify the dependencies in the relation.

41
LIBRARY (member_id, member_fname, member_fname, book_code,
book_name, issue_date, issue_return)

member_id (determines) -> member_fname, member_lname (1)


book_code (determines) -> book_name (2)
book_code, member_id, issue_date (determine) -> return_date (3)

member_id member_fname

member_lname
book_code
book_name

issue_date return_date

The following relations/tables are created.


MEMBER (member_id, member_fname, member_lname) (From FD 1)
BOOK (book_code, book_name) (From FD 2)
ISSUE (book_code, member_id, issue_date, return_date) (From FD 3)
42
3NF (Third Normal Form)
• A table or relation is in 3NF if it is in 2NF
and there is no transitive dependency
among the attributes in the relation.
• A transitive dependency is: if A, B, and C
are the attributes in a relation R and A->B,
B->C then we can derive A->C using
functional dependency.
• There is no transitive dependency in the
above relations, thus the relations also are
in 3NF.

43
Types of database

• Centralized database system


• Distributed database system

44
Centralized database system
• The database is stored in one main computer, called
database server and many terminals are connected to
the server with the help of network media.
• All data processing jobs are carried out in the server.
• Terminals have no ability to process or store data, its
just like interface to access database in server.
• It is simple types of database processing system with
low operating cost, low installation cost and limited
facilities.
• Data traffic might high in centralized database server.
• It is based on client-server architecture.

45
Terminal 1

Network Server
Terminal 2
DB

Terminal 3

Fig: Centralized database system

46
Distributed database system
• The database is stored and processed in different
servers at different sites.
• Network communication media links the servers.
• The network might be LAN (Local Area Network) or
WAN (Wide Area Network).
• This system is based on distributed client-server
architecture where database is maintaining in
different servers with the help of different clients
associates with the servers respectively.
• Each server has equal privileges to access database
of itself and other servers in the system.
• So data traffic is comparatively very low in
distributed database system.
• This is a modern sophisticated database system
with high facilities and high operating cost.
47
C C C
1 2 3
DB1
DB2
DB3 Server 1
DB4
DB
C C C C
1 2 1 2
DB1
Network DB2
DB1 Server 4
DB2 Server 2 DB3
DB3 DB4
DB4 DB
DB

DB1
Server 3 DB2
DB3
DB4
DB
C C
1 2

Fig: Distributed database system

48
Data Integrity and Data Security
• Data Integrity referees to the validity or consistency of
data in database. It ensures that the data should be
accurate and consistent.
• This is done by using different types of constraints
(rules) called integrity constraints.
• Ex 1: age of an employee is between 16 and 70
• Database security is protection of information in
database against unauthorized access, modification or
destruction.
• The authorized access means only right people can get
the right access to the right data.
• There are different causes of database destruction. It
might be accidental loss or physical damage in
computer system or. natural calamities.
• Different types of data recovery, data locking
techniques and (RAID: Redundant Array of
Independent Disk) are used.
49

You might also like