Unit - 3 Unit - 3 Data Base Managemant Data Base Managemant

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

UNIT – 3

Data Base Managemant

Unit 3.1 Data Base Concepts


DBMS :: (Data Base Management System)
A DBMS refers to a s/w that is responsible for storing,
maintaining and utilizing databases. DBMS is basically a
record keeping system. Ex of DBMS are MS Access, MY
SQL , SQL Lite, MYSQL server , Oracle , FoxPro , Dbase etc.

Data Base:: Data base is defined as the organized


collection of data. Ex: Attendance register , Telephone
directory

Need of DBMS:: Basic needs of DBMS are


1.Data bases reduces data redundancy:: Data redundancy
means duplication of data. Ex: In a college, student’s
records are maintained and the hostel also maintains
record of all those students who live in hostel. Both
college and hostel maintains a separate copy of student
record. But duplication of data may lead to inconsistency.

Suppose the permanent address of a hostler gets


changed. The hostler student informs about it to the
hostel authorities and the changed address is reflected in
the student’s record. The data for the same student has
not been changed in the college records. If the students
forgets to inform the college authorities or college people
themselves forget to update the student’s record, the
same student’s record differ in two different files

Now which record of the two would be considered accurate.


Suppose college has to send certain information by post.
Then what will happen. The wrong data will get processed.

Data bases control data inconsistency::Inconsistency


means in correct information(Changes made at one place is
not reflected at other place).By controlling redundancy ,
inconsistency can be controlled.

Data base facilitate sharing of data:: Sharing of data means


data in the database may be shared among several different
users. Each user may have access to the data and each of
them may use it for different purposes .For sharing of data
grant command is used.
Data bases enforces standards:: Data base standards are
related to the naming of data , structure of data , format
of data etc.
Standards used in DBMS are
(a). Give meaningful field name
(b).Use consistent data type ie. Don’t use phone _no as
numeric in one table and char in other table. Same field
name in two tables should have same data type.
(c). Don’t use space in table name or field name.

Data base can ensure data security:: Data security means


protection of data against unauthorized person.
To secure database username and passwords must be
applied.
create user <username> identified by <password>

Integrity can be maintained through database:: Data integrity


means accuracy and consistency of data. Data integrity can
be maintained by various error checking and validation
methods.

Data validation :: Let the date format is save as dd/mm/


yyyy format in SQL then date must be in dd/mm/yyyy format
and not in sep 2nd 2007.This is called data validation. There
are two basic rules to ensure data integrity.

a). Entity Integrity :: This rule ensures that every table must
have its own primary key.
b). Referential Integrity :: Referential integrity is based on
primary and foreign key. This rule defines that a foreign key
have a matching primary key.
Table:: Employee
Foreign key

Emp_id Emp_name Dept_id

Primary
Table:: Department key

Dept_id Dept_name Dept_zone

This rule states that the Dept_id(Foreign key) in the


Employee table has a matching valid Dept-id(Primary key)
in the department table.

DataBase Abstraction:: Database Abstraction means


to provide the users only that much information that is
required by them or we can say that the system does
not disclose all the details of data rather it hides certain
details of how data is stored and maintained.
Example :: In a bank database if a customer wants to
know his balance then he is concern to only that part
not even all his details that how his database is stored ,
where is stored and all that.

Levels of Database Abstraction:: There are 3 levels of


database implementation.
1. Internal level
2. Conceptual level
3. External level
Internal level :: Internal level is also called physical level or
storage level. It describes how data are actually stored in
the storage medium.

Conceptual level :: Conceptual level is also called logical


level. It describes what data are actually stored in the
database. This level is related to the structure of the
database.

External level :: External level is also called view level. It


describes the way in which the data are viewed by the
users. Most of the users of the database are not concerned
with all the information contained in the database. Instead,
they need only a part of the database relevant to them.

pPhysical Level

Sales officer (T1) Item_no integer Item_no type=byte(38),offset=5


Item name
price Item_name char(10) Item_name type=byte(38),offset=7

Purchase officer (T2) Price integer Price type=byte(38),offset=36


Item name
Quatity Quantity integer Quantity type=byte(34),offset=15
Concept of Data Independance:: The ability to modify a
scheme definition in one level without affecting the
scheme definition in the next higher level is called Data
Independence. There are two levels of data independence.
1) Physical data independence
2) Logical data independence

Physical data independence:: Modify the scheme


followed at the physical level without affecting the
scheme followed at the conceptual level.
Any of the below change in physical level will not affect
the conceptual level.

Using a new storage device like Hard Drive or Magnetic


Tapes.
Change of Location of Database from say C drive to D
Drive

Logical data independence:: Modify the scheme followed


at the conceptual level without affecting the scheme
followed at the external level.

Any of the below change in conceptual level will not affect


the external level.

Add/Modify/Delete a new attribute


Merging two records into one
Breaking an existing record into two or more records
Unit 3.2 Relational Data Model
Data Models :: Data models are basically concepts that can
be used to describe the structure of a database .The three
data models are used in database management system.
Relational data model
Network data model
Hierarchical data model

1. Relational data model:: In relational data model data is


organized in the form of tables. These tables are called
relations. Relationship b/w record is represented by
relation containing keys.
Let there are three tables(relations)
Suppliers , Items , Shipments
Rows in a relation are generally referred to as tuples and
columns in a relation are generally referred to as
attributes.
2.Network data model:: In Network data model data is
organized in the form of graph structure. Relationship b/
w record is represented by links.

3.Hierarchical data model:: In Hierarchical data model data


is organized in the form of trees. Relationship b/w record
is represented by trees(parent child form).
Root
Tree Structure

S1

I2

I3 10

I6
20

20

Relational Data Models :: Relational data model was


developed by E.F Codd. In this model data is organised in
two dimensional table called relation.

Basic terms used in Relational database ::


Entity :: Name of the table
Relation :: Relation is a table , consists of tuples (rows) and
attributes(columns).A relation must have following
properties.
An item in a given column are of same kind.
All rows of relation must be distinct
Column name of a relation are assigned distinct names.
 Each row must be uniquely identified
Domain :: A domain is a pool of values from which actual
values appearing in a given column are drawn.

S1 S2 S3
S4 S5 S6 S7

Suppno is drawn from above domain in “suppliers” table.


Tuple:: The row of a table is known as tuple.
Attribute :: The column of a table is known as attribute.

Cardinality :: The number of tuples in a relation is known as


cardinality. In suppliers table, the cardinality is 5.

Degree:: The number of attributes in a relation is called


degree. In suppliers table, the degree is 4.

Component of Relation ::
Table :: Table is composed of records and fields that hold
data.

Record:: Records contain all the data about one particular


person and composed of fields.

Fields:: Smallest piece of meaningful information is called


field.
Data Item:: Values stored in a table are called data items.

Keys:: Key is an attribute which identifies records in a table.


There are different type of keys in RDBMS.
Primary Key :: An attribute which identifies each record in a
table is called primary key.

Table :: Student
Primary key

StuId Roll No FirstName LastNmae Email


1 11 Neha Singh neha@gmail.com
2 12 Tom Andrews tom@gmail.com
3 13 Prachi Gupta prachi@gmail.com

Candidate Key :: Candidate Key is a set of attributes that


uniquely identify tuples in a table. The Primary key should
be selected from the candidate keys. A table can have
multiple candidate keys but only a single primary key.

Candidate Key
Primary key
Alternate Key :: A Candidate key that is not the primary key
is called the Alternate key. Alternate key is also called
secondary key.
Candidate Key
Primary key

Alternate
key

Foreign Key :: Foreign key is used to represent relationship


between two tables. A non key attribute of a table, which is
primary key for some other table is called foreign key. A table
that contains foreign key is called foreign table(child table or
detail table). A table that contains primary key is called
foreign table(primary table or master table).
Table:: Employee
Foreign key

Table:: Department Primary


key
Key Attribute :: Attributes that participate in the candidate
key are the key attributes.

Non Key Attribute :: Attributes other than candidate key in a


relation are called non key attributes.

Relational Algebra:: (procedural language) Relational


algebra is a collection of operations(Unary and Binary
operations)
Unary Operations :: They operate on one relation. Example ::
Select , Project
Select Operation:: Select operation is denoted by sigma(σ)
operation. Tuples are selected in select operation

Select σ price>14 (Items) Relation name


operation

Condition

Consider Table :: Items


After applying the above condition in items table , following
output will be generated

Item# Item_Name Price


I1 Milk 15.00
I7 Icecream 16.00
I9 Namkeen 15.00
σCity=“Delhi”(Suppliers)

Supp# Supp_Name Status City


S1 Britania 10 Delhi
S3 Mother Dairy 10 Delhi
σPrice>5.00 ^Price<9..00 (items)
(Those tuples are selected whose price lies between 5 t0 18)

Item# Item_Name Price


I5 Plain Biscuit 6.00
(AND sign)
(OR sign) I8 Cold Drink 8.00

Project Operation:: Project operation is denoted by pie(Π)


operation. Attributes are selected in project operation.

Π Supp_Name , City (Suppliers)

Project operation Relation name


Condition

Consider Table :: Suppliers


After applying the above condition in Suppliers table , following
output will be generated.
Supp_Name City
Britania Delhi
New Bakers Mumbai
Mothers Diary Delhi
Cookz Banglore
Haldiram Jaipur

Π City(Suppliers)

Duplicacy isCity
automatically removed in above query.
Delhi
Mumbai
Banglore
Jaipur

ΠItem_Name(σPrice>14.00(Items))

Item_Name
Milk
Ice Cream
Namkeen

Binary Operations :: They operate on two relations


Example :: Cartesian Product ,Union , Set difference , Set
intersection
Cartesian Product:: Cartesian product is denoted by X
sign.
Cartesian product yields a all possible combinations of
tuples of relation A and relation B.
Table :: Student

Stud# Stud_Name Hosteler


S001 Neha Y
S002 Radha N
S003 Abhi N

Table :: Instructor

Inst# Inst_Name Subject


101 K.Lal English
102 R.L Arora Maths

Cartesian Product of two relation Student X Instructor

Stud# Stud_Name Hosteler Inst# Inst_Name Subject


S001 Neha Y 101 K.Lal English
S001 Neha Y 102 R.L Arora Maths
S002 Radha N 101 K.Lal English
S002 Radha N 102 R.L Arora Maths
S003 Abhi N 101 K.Lal English
S003 Abhi N 102 R.L Arora Maths
Union Operation:: Union operation is denoted by U sign.
The resultant relation will contain all the tuples of relation
A and relation B.

Table :: Drama
Roll _No Name Age
13 Kush 15
17 Swati 14

Table :: Song

Roll _No Name Age


2 Maya 15
10 Riya 15
13 Kush 15

Drama U Song

Roll _No Name Age


2 Maya 15
10 Riya 15
13 Kush 15
17 Swati 14

Answer the given query on the basis of given table Customer.


(σCust_Name=Banker_Name(Customer))U(σamount>Balance(Customer))

Cust# Cust_Name Banker_Name Amount Balance


C001 Abju Riya 17510.00 17510.0
0
C002 Reeva Reeva 21000.00 22300.0
0
C003 Astha Neha 25199.00 24801.0
0
Cust# Cust_Name Banker_Name Amount Balance
C002 Reeva Reeva 21000.0 22300.00
0
C003 Astha Neha 25199.0 24801.00
0
Set difference Operation:: Set difference operation is denoted
by - sign.
The resultant relation will contain those tuples that are in A but
not in relation B.

Table :: Drama

Table :: Song

Drama – Song

Roll _No Name Age


17 Swati 14
Set intersection Operation:: Set difference operation is denoted
by n sign.
The resultant relation will contain those tuples that are
common in both relation.
Table :: Drama

Table :: Song

Drama n Song

Roll _No Name Age


13 Kush 15

You might also like