You are on page 1of 63

Database Management System

Walkthrough . . . .
j j j j j j j j

Hierarchy of Data Traditional Approach & Drawbacks Database Approach Data Models Emerging Database Trends Entity Relationship Modelling Normalization Overview of SQL

Hierarchy of Data
j Bit -A bit represents a circuit that is either on/off (1/ 0) j Byte - A byte is usually 8 bits, representing a character j Record - A collection of related fields is a record (Ex 05BS-0045 Amit Kumar Singh) j File - A collection of related records is a file (05BS- 3567 Avinash Singh 05BS- 4456 Rajan Khetarpal ) j Databse - A collection of integrated and related files is a database

Traditional Approach
j One or more data files created and used for every

application. Ex : Invoicing program would have files on customers and inventory items being shipped j Possible to have the same data in several files used by different applications.

Drawbacks of Traditional Approach


j Increased Data Redundancy resulting from the

duplication of data j Lack of Data Integrity resulting from the duplication of data j Program-Data-Dependence
Data developed and organized for one application are incompatible with data from another application

j Difficult to modify and update application

programs and data

Database Approach to Data Management


j Separate data files are reorganized into a pool of

related data so that each data element is stored and maintained only in one location. j Related data is shared by multiple application programs. j Database Management System (DBMS) is required.

Database Management System


j A DBMS is a data storage and retrieval system

which permits data to be stored non-redundantly while making it appear to the user as if the data is well-integrated j Collection of interrelated data j Set of programs to access the data j DBMS contains information about a particular enterprise j DBMS provides an environment that is both convenient and efficient to use
7

Database Management System


Application #1

Application #2

DBMS
DBMS manages data resources like an operating system manages hardware resources

Database containing centralized shared data

Application #3

Basic Concepts
j File
A set of related records Name: Barry Harris College: Medicine Tel: 392-5555 Name: Barry Harris College: Medicine Tel: 392-5555 Name: Barry Harris

jRecord
- A collection of Data about an individual item

jField

- A single item of data common to all records


9

An Example of a Database

Records

NAME Graff Harris Ipswich

GL rgraff bharris zipswich

PHONE 392-3900 392-5555 846-5656

COLLEGE Pharmacy Medicine Health Professions

Fields

10

Tables and Relationships


j Person takes many Surveys
Surveys consists of many Questions
Demographics

Name GL Phone College

Surveys Survey Supervisor Peers GL

Questions Leadership Likeable Fair Survey

11

Basic Design Rules


j Unique records j Unique fields j Independent fields j No calculated or derived fields j Data is broken down into smallest

logical parts
12

Benefits of Database Approach


j Data can be shared j Reduced redundancy of data (Storage) j Inconsistency can be avoided (Updates) j Improved data integrity (Correctness/Constraints) j Increased security j Conflicting requirements can be balanced j Standards can be enforced j Increased user productivity

13

Drawbacks of Database Approach


j Relatively high cost of purchasing j Requires specialized staff to implement and

coordinate the use of the database j Increased vulnerability due to failure of the DBMS or access to the entire database by an intruder

14

Data Modeling
j Content - What data should be collected? j Access - What data should be given to what

users? j Logical structure - How will the data be organized to make sense to a particular user? j Physical organization - Where will the data actually be located?

15

The 3 Schema architecture for a database system

Users External Level

Logical Database Administrators => What Data and Relationships Level

=> How Data are Stored


16

Physical Level

Levels of Abstraction
j Physical/ Internal level describes how a record

(e.g., customer) is stored. j Logical/Conceptual level: describes data stored in database, and the relationships among the data. type customer = record name : string; street : string; city : integer; end; j External/View level: application programs hide details of data types. Views can also hide information (e.g., salary) for security purposes.
17

Data independence
j A user of a relational database system should be able to

use SQL to query the database without knowing about how precisely data is stored, e.g. SELECT name, address FROM Student WHERE name = Rajan;
j After all, you don't worry much how numbers are stored

when you program some arithmetic or use a computerbased calculator.

18

More on data independence


j Logical data independence protects the user from changes in the logical structure of the data -- could completely reorganize the calendar schema without changing how I query it. j Physical data independence protects the user from changes in the physical structure of data: could add an index on Who without changing how the user would write the query, but the query would execute faster (query optimization).

19

Managing Data Files


j Character A basic unit of data (e.g., number) j Field A collection of related characters (e.g., customer name) j Record A collection of related data fields j File A collection of related records

20

Data Models
j A collection of conceptual tool for describing data,

data relationships etc j 3 categories defined j Object Based Logical Model Entity Relationship Model j Record Based Logical Model Relational Model Network Model Hierarchial Model j Physical Models
21

Entity-Relationship Modeling
j Entity object, event or agent about which data are

collected. j Attribute item of data that characterizes an entity j Composite attributes consist of several subattributes j Attributes must be sufficient to uniquely identify every entity in a database j Key attribute has unique value for every entity

22

Developing Model Representations for Entities and Attributes

FIGURE 3.9b

23

Relationships
j Relationship association between entities j Strategy for identifying entity relationships

affecting the logical design of a database


Consider existing and desired information requirements of users Evaluate entity pairs to improve attribute descriptions of entities Evaluate each entity to identify recursive relationships among entities

24

Modeling Relationship Types

FIGURE 3.11

25

Entity-Relationship Model
j An entity is an object that exists and is

distinguishable from other objects. Example: specific person, place, company, object, event, concept ( often corresponding to a row in a table )
j Entities have attributes..property or characteristic

of an entity type ( often corresponding to a field in a table ) Example: people have names and addresses
26

Entity Sets
j An entity set is a set of entities of the same type that

share the same properties. ( Entity Type . Collection of entities ( often corresponding to a table ) Example: set of all persons, companies, trees, holidays j Entity Instance A single occurrence of an entity type.
j Relationship instance link between entities j Relationship type category of relationshiplink

between entity types


27

Attribute - property or characteristic of an entity type


j An entity is represented by a set of attributes, that is

descriptive properties possessed by all members of an entity set.


Example: customer = (customer-id, customer-name, customer-street, customer-city) loan = (loan-number, amount)

j Domain the set of permitted values for each

attribute j Attribute types: Simple and composite attributes. Single-valued and multi-valued attributes
E.g. multivalued attribute: phone-numbers

Derived attributes
Can be computed from other attributes
28

Relationship symbols

Entity symbols

Attribute symbols

A special entity that is also a relationship

Relationship cardinalities specify how many of each entity type is allowed


29

Relationship degrees specify number of entity types involved

E-R Diagrams

 Rectangles represent entity sets.  Diamonds represent relationship sets.  Lines link attributes to entity sets and entity sets to relationship sets.  Ellipses represent attributes  Double ellipses represent multivalued attributes.  Dashed ellipses denote derived attributes.  Underline indicates primary key attributes
30

Figure 3-4

Inappropriate entities

System user

System output

Appropriate entities

31

A composite attribute

An attribute broken into component parts

32

Simple key attribute

The key is underlined

33

Composite key attribute

The key is composed of two subparts

34

An attribute that is both multivalued and composite

This is an example of time-stamping


35

Entity with a multivalued attribute (Skill) and derived attribute (Years_Employed) Whats wrong with this?

Derived
from date employed and current date

Multivalued:
an employee can have more than one skill

36

What Should an Entity Be?


j SHOULD BE: An object that will have many instances in the database An object that will be composed of multiple attributes An object that we are trying to model j SHOULD NOT BE: A user of the database system An output of the database system (e.g. a report)

37

Relational database
j Most common j Data is organized in a collection of tables (relations) j Rows tuples (records) j Columns attributes (fields)

38

Example of a Relation (EMPLOYEE) and Its Parts

FIGURE 3.10

39

Relational Model
Attributes

j Example of tabular data in the relational model


Customerid 192-83-7465 019-28-3746 192-83-7465 321-12-3123 019-28-3746 customername Johnson Smith Johnson Jones Smith customerstreet Alma North Alma Main North customercity Palo Alto Rye Palo Alto Harrison Rye accountnumber A-101 A-215 A-201 A-217 A-201

40

A Sample Relational Database

41

The Relational Model


j Views entities as two-dimensional tables

Records are rows Attributes are columns j Tables can be linked j Supports one-to-many, many-to-many, and oneto-one relationships

42

Associations
j Relationships among the entities in the data

structures j Three types One-to-one One-to-many Many-to-many j Relationships set by placing primary key from one table as foreign key in another Creates acceptable redundancy

43

Cardinality of Relationships
j One-to-One Each entity in the relationship will have exactly one related entity j One-to-Many An entity on one side of the relationship can have many related entities, but an entity on the other side will have a maximum of one related entity j Many-to-Many Entities on both sides of the relationship can have many related entities on the other side
44

45

46

Sample E-R Diagram

47

Identifiers (Keys)
j Identifier (Key) - An attribute (or combination of

attributes) that uniquely identifies individual instances of an entity type j Simple Key versus Composite Key
A super/ composite key of an entity set is a set of one or more

attributes whose values uniquely determine each entity.


A candidate key of an entity set is a minimal super key
Customer-id is candidate key of customer account-number is candidate key of account

Although several candidate keys may exist, one of the candidate

keys is selected to be the primary key.


48

Normalization

49

Normalization
j Process of efficiently organizing data in a

database j Goals of normalization: Eliminate redundancy Ensure data dependency makes sense
 Advantage : j Complex databases are made simpler j Reduces the amount of space utilized j Ensures data is logically stored.
50

Normalization Defined as :- Process of restructuring a


relation (table) for reducing it to a form where each domain will consist of single, noncomposite values.
j Its a step by step procedure & steps are called

FORMS. j Normal forms are numbered from lowest 1st through 5th. j NFs are table structures with min. redundancy.
51

Contd
j The process of decomposing relations with

anomalies to produce smaller, well-structured relations General rule of thumb: a table should not pertain to more than one entity type

52

Well Structured Relation


A relation that contains minimal data redundancy and allows users to insert, delete, and update rows without causing data inconsistencies j Goal is to avoid anomalies Insertion Anomaly adding new rows forces user to create duplicate data Deletion Anomaly deleting rows may cause a loss of data that would be needed for other future rows Modification Anomaly changing data in a row forces changes to other rows because of duplication
53

Redundant Data

54

Anomalies in this Table


j Insertion cant enter a new instructors record,

without entering student information. j Deletion if we remove Hanns record, we lose information about the existence of a Database class j Modification changing a course instructor forces us to update multiple records
Why do these anomalies exist? Because weve combined multiple themes (entity types) into one relation. This results in duplication, and an unnecessary dependency between the entities
55

Some Terms to Know :


j Functional dependency Attribute Y is

functionally dependent on attribute X, if the value of X determines the value of Y.


Ex : Students phone no can be obtained looking up the name of the student.

j Candidate Key

56

First Normal Form


j Remove all repeating groups. j Eliminate duplicate columns j Identify each row with a unique column/set of

columns (Primary Key)

57

Second Normal Form


j Relation should be in 1st NF. j Every non-key field is fully dependant on PK j Remove duplicate data i.e data that apply to

multiple rows of a table. j Place these multiple rows in separate table. j Create relationship between new table & predecessor table using FK.

58

Third Normal Form


j Relation should be in 2NF j Remove columns not dependent on PK.

Fourth Normal Form j No multivalued dependency.

59

Steps in Normalization

60

Normalized Data

61

Popular Database Management Systems

World wide database Market Share 2001 Based on percentage of worldwide new licence revenue from DBMSs

62

Summary Slide
j The Hierarchy of Data j The Traditional Approach to Data Management j Problems with the Traditional Approach to Data j j j j j j j j j j

Management The Database Approach to Data Management Disadvantages of the Database Approach How to Perform Data Analysis Step 1: Define the needed fields Step 2: Select the required entities Step 3: Create a Relational Data model Step 4: Normalize the Data Model Parameters to Consider when Selecting a DBMS Emerging Database Trends Hands-On Microsoft Access 2000
63

You might also like