Sei sulla pagina 1di 33

FOCARS’ 85

Overview of Database
Management Concepts
NH Rao
Feb 20, 2009
Learning Objectives

 Recognize data as a manageable resource


 Understand the advantages of the database
approach
 concepts of database management systems
(DBMS)
 Introductory skills in MS Access

Feb 20, 2009 2


Data - Information – knowledge - wisdom…
Data
Known facts that can be recorded

Information
Transformed/processed data that has been given meaning by
way of relational connection
= Data + Purpose + organization = DBMS

Knowledge: synthesized information for use


= Model, AI

Wisdom:
Extrapolative knowledge (experience/intuition)
= prediction, Principles
Feb 20, 2009 3
Why manage data in agricultural research?
• data are valuable resources generated after investments
• data are large and complex - generated in multiple plots/
locations and over seasons
• data need to be shared among multiple users/applications
• data need to be updated frequently
• record keeping for intellectual property protection/
biodiversity management/environmental regulations
• many applications – GIS, bioinformatics/plant, livestock,
fish genomics – built around existing DBMS
• for policy, principles, guidelines
Feb 20, 2009 4
Examples of Databases
• Paper sheets in numbered files
• Library books
• Telephone directory
• Dictionary Common feature
• Maps Huge amount of
• Soil samples structured/organized
• DNA samples information that can be
accessed and used
• Germplasm collections
efficiently
• Gene sequences
• Dispatch register
• Computer databases: text, numbers, visual
images, audio images, etc.; in file based
systems, DBMS
Feb 20, 2009 5
Conventional approach to data management
– File based systems

Fig source: NIC

Feb 20, 2009 6


Database approach

Database: collection of non-redundant data which can


be shared by different application systems
implies
- program & data independence
- many users can share data
(without bothering about about
how database was created)
- changes can be made to
components of data without
affecting other components of
the system.

Feb 20, 2009 7


Database structure

1. Flat file: single table


Advantages : simple, suitable
District Area (‘000 Average
ha) rainfall (mm)
for few columns and rows of
Aaaa 2000 650 data
Bbbb 3000 700 Examples: spreadsheets (MS
Cccc 1500 800 Excel), Tables (MS Word)
With increase in complexity (more attributes & rows):
District Area Average Year Rice_area Rice_prodn Disadvantages:
(‘000 ha) rainfall (ha) (tonnes)
(mm) - redundancy
Aaaa 2000 650 1990 100000 150000
Aaaa 2000 650 1991 105000 180000
(repetitive data entry)
Aaaa 2000 650 1992 110000 119000 - inconsistency
Bbbb 2500 700 1990 112350 203450 (changes in data
7

difficult to implement)

Feb 20, 2009 8


Database structure (contd …)
2. Relational database structure - Split data into related tables to avoid/
minimize redundancy and inconsistency …..
DISTID District Area (‘000 Average
ha) rainfall
(mm)
1001 Aaaa 2000 650
Table 1

Related Tables
1002 Bbbb 3000 700
Independent
1003 Cccc 1500 750
Relate/connect by common identifier
DISTID Year Area_rice Prod_rice
(ha) (tonnes)
1001 1990 100000 150000
Table 2 1001 1991 105000 180000
Related 1001 1992 110000 119000
1002 1990 112350 203450
1002 1991 113000 220000
7

Feb 20, 2009 9


Relational Databases

• eliminate/reduce redundancy and inconsistency


of data by splitting data into several tables and
establishing relations between them
• the splitting is such that each table represents
one entity – object, person, category, theme, etc.
– with some common feature with other tables to
connect/ relate to them

Feb 20, 2009 10


Relational database – example

Employee database

leave
Independent Employees
Table Pay
Projects

Training
Broad categories/themes
of related information /
entities – related tables

Feb 20, 2009 11


Employee database : An example
Employee
Details
Emp Code Takes Leave
Emp Code
Name Leave type
Designation
DOJ Leave Start date
EL at Credit Leave End date
CL at credit Emp Code Duration
Basic pay
DA
HRA • Leave data entry
Conveyance • Reports/ Queries

Feb 20, 2009 12


Relational databases - example

Agricultural
resources
database
Independent
District
Table/entity
fruits

Cereals
vegetables

Soils
Related Tables/
Weather Entities
Livestock

Feb 20, 2009 13


Database Organization:Terms

• Entity: distinguishable real world object - person, place,


event or thing - about which data of attributes is
maintained (also called Table, Object, Relation)

• Fields: attributes/properties/characteristics that describe


an entity (column headings in a table)

• Record:set of values of fields for one occurrence of the


entity (row, instance, tuple)

• Table/File: set of records for the entity


• Database: Related tables
Feb 20, 2009 14
Physical organization of data in a RDBMS

Database – related tables collection of related tables


User controlled

Relation - File/table collection of related records

set of related items


Record (row of data in table)

Field set of characters forming one item

bytes
Hardware
controlled

bits

Adopted from Briggs, UT Dallas

Feb 20, 2009 15


Database organization - Terms (contd…)

eg: Entity - Districts FIELD

DISTID District Area Average


(‘000 rainfall
ha) (mm)
1001 Aaaa 2000 650
1002 Bbbb 3000 700 RECORD
1003 Cccc 1500 750
No.of rows = No. of records

Required Information about Fields


Name, data type (text, number, etc.), data size, Format
(optional - comments or notes describing the data)

Feb 20, 2009 16


Relational Database structure
Entity-Relationship model
Split data into more entities/tables and establish
relationships through a common filed
Rice_area
area year
name
Average
DISTID rainfall DISTID Rice_prodn

District produces rice

Basic objects of the model are:


Entities
Attributes
Relationships
Feb 20, 2009 17
Organizing Data – Rules for Table design
• Separate table for each set of related attributes
• For each table to be a relation:
• single value in each cell (no arrays/groups)
• unique name for each column
• same data type for all entries in a column
• no duplicate rows or columns (1- NF)
• must have a primary key - a unique identifier for a row
• all attributes in a row must be functionally dependent on
the primary key (2-NF, 3-NF)
As a result :
• If each record within the table is different in some way, the primary key
helps to easily identify and access different records
• information
Feb 20, 2009
content of a table does not depend on the order of the rows18or
the order of the columns
Relational Database features
Entity: DISTID District Area (000 Average rainfall
INDEPENDENT
Districts ha) (mm)
1001 Aaaa 2000 650 TABLE
1002 Bbbb 3000 700
1003 Cccc 1500 750
DATA
PRIMARY KEY COMMON FIELD INTEGRITY MUST
Entity: BE MAINTAINED
No DISTID. Year Area_rice Prod_rice
Rice (ha) (tonnes) BETWEEN TABLES
1 1001 2000 100000 150000
2 1001 2001 105000 180000 RELATED TABLE
3 1001 2002 110000 119000
4 1002 2000 112350 203450 One-to-many
5 1002 2001 113000 220000 relationship
7

FOREIGN KEY Database structure = {Tables + Keys + Relationships}


Feb 20, 2009 19
Relational database features (contd..)
Basic data of districts – Independent table
DIST Distname Statename
1001 aaaaa bbbbb

Common field = DIST


Area and production of cereals – Related Table 1
Primary NO DIST Year Rice_ka Rice_kp Wheat_a Whe
key p
1 1001 1990 RA1 RP1 WA! WA2
2 1001 1991 RA2 RP2

Fertilizer use – Related Table 2


NO DIST Year N P K
1 1001 1990 N1 P1 K1
Feb 20, 2009 20
2 1001 1991 N2
Primary Key

Primary key is a Field (attribute/column), that


uniquely identifies each record in the table

NOTE:
•Choice of primary key is usually obvious from the
structure of the Table.
• If there is no easy natural choice for a primary key
add a column containing a unique identifier (serial
number)
• Data in every column of the row must be dependent on
the primary key

Feb 20, 2009 21


Foreign key and referential integrity
Foreign key: Primary key of the independent table
maintained as non-primary key (common field) in related
table

Referential integrity: maintains validity of foreign keys in


related tables when primary key in independent table
changes
NOTE:
• every foreign key matches a primary key or is a null
• cascade rules apply to primary and foreign keys for
referential integrity

Feb 20, 2009 22


Representing relationships

• entities are drawn as boxes


• relationships are drawn as lines between boxes connecting
common fields (primary key in independent and foreign key
- common field) in related tables)

Districts Rice
NO
DISTID
DISTID
Name Year
Average Rice_area
rainfall Rice_ production

Feb 20, 2009 23


Example: AGMIS database structure

Feb 20, 2009 24


In a relational data base:

Relationships and keys allow data in different


Tables to be treated as if they were in one table
to:

• identify and extract relevant information from


several tables (read data)

• enter data into different tables simultaneously

Feb 20, 2009 25


RDBMS in a nutshell
Related
Queries ( Need not collection of Forms for Data Entry &
preplanned) Data consisting User Interface
of tables
Reports
A Table (Structures& Preplanned)
consists
of

Record(s)

A record
consists
of
Key field(s), used for setting
relations between tables
whose values should be
unique
Type of Field
Data item(s) Numeric (of fixed length)
Character (of fixed
length)
Date
Logical Fig source:
Memo (of variable length)
Normal data field(s) Bit Ma p
Etc
Summary of key concepts of database design
• Assemble attribute variables (fields, data types)
• Group fields into Entities (Objects/Tables)
• Identify Primary Key field for each entity/table
• represent entities as boxes with listed fields
• Identify independent/related entities/tables
• Identify common field between independent and
related tables
• Establish Relationships by connecting the common fields
• Ensure Referential Integrity between independent and
related tables
Feb 20, 2009 27
When a DBMS may be unnecessary

• If the database and applications are simple, well


defined, and not expected to change

• If access to data by multiple users is not required

Feb 20, 2009 28


Database Management System
DBMS = {Database + Software that enables database
design and use}
Functions of software include :
- Create database structures (tables, relationships)
- Enter data and edit / update Tables
- Answer questions that you ask of data in Tables
- Generate reports after analysing data in Tables
- Provide security
MS Access = relational DBMS

Feb 20, 2009 29


MS Access components
• Tables - contain data
• Forms - user interfaces to enter data
• Queries - find and retrieve data, and simple analysis
• Reports – print/present data
• Pages - Publish the data on the web using Pages
• Macros / Modules - add more functionality
• Database Wizards
- Mini programmes that interact with the user
- Create database structures for each object
- User only needs to choose among a range of
database structures (for Tables, Forms, Queries,
Reports) and enter data
- Make Access a useful tool for novices and
professionals
Feb 20, 2009 30
Designing a Database in MS Access (summary)
Identify purpose

Assemble Fields (Data attributes)

Design Tables:
 Group attributes into tables (relations)
 Make a separate table for each set of related attributes, and
give each table a primary key
 Eliminate redundant data (derived data)
Use database wizards to
 Create tables
 Create relationships between tables
 Create forms to enter data
 Add data and create other database objects
Feb 20, 2009 31
Guidelines for designing database Tables
• Each table should contain information about only one
subject
• Each field should be related directly to the subject of the
table
• Derived or calculated data should not be included in tables
• Information must be stored in its smallest logical parts

• Tables and Forms need to be planned carefully

• Queries and reports can be generated when required


Feb 20, 2009 32
Exercise
To design a prototype district level Rice Production
Information System (RPIS) for Andhra Pradesh.
Given:
(i) Table of districts
(ii) Data of rice production 1993-97 (Sheet 1)
(iii) Data of rice area 1993-97 (Sheet 2)
To design:
(i) Database structure ( assemble fields, design tables and
create relationships)
(ii) Form for entering rice production data
(iii) Form for entering rice area data Refer to practical
manual
(iv) Query and reports for rice yield charts

Potrebbero piacerti anche