relational databases

17

Click here to load reader

Upload: jason-hando

Post on 05-Dec-2014

958 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Relational Databases

1

Introduction to Relational Databases 1

Page 2: Relational Databases

2

Relational Databases

As information needs grow and become more complex, so to do methods of storing, managing and retrieving the data.

Database systems evolved to manage this information and data.

Page 3: Relational Databases

3

Relational Databases

The relational model was developed in 1970 by E.F. Codd

The basic data components in a relational database are "entities" and their "attributes" and the basic logical structure is a "table".

Page 4: Relational Databases

4

Components

Entities A "thing" in a real world with an

independent existence. Something about which you want to store data typically: a person, place, object, concept, or event.

Page 5: Relational Databases

5

Components

Attributes A characteristic of an entity or object. A

detailed piece of information that describes an entity.

Tables Each table is a separate and independent

unit - although tables may be related

Page 6: Relational Databases

6

The Relational Database Model The simplest model for a database is a

flat file. You have only a single table which

includes fields for each element you need to store.

The problem with flat files is that they waste storage space and are problematic to maintain.

Page 7: Relational Databases

7

Flat Files

Data redundancy storing the same information in more than one

file. E.g. a customers address stored in more than

one file.

Data integrity maintaining accurate data. If a customer’s

address is changed will it be changed in all files? If not the data loses it’s integrity - it is inaccurate.

Page 8: Relational Databases

8

Example

Customers Customer Number Company Name Address City, State, Phone Number

Orders Order Number Order Date

Order Line Items Item Number Description Quantity Price

Each time an order is placed, you'll need to repeat the customer information, including the Customer Number, Company Name, etc.

Each time an order is placed, you'll need to repeat the customer information, including the Customer Number, Company Name, etc.

A company which takes orders from many

customers

Page 9: Relational Databases

9

Solution

The solution to this problem is to use a relational model for the data.

This means that in this example each order entered is related to a customer record, and each line item is related to an order record.

Page 10: Relational Databases

10

Solution

A relational database management system (RDBMS) is a piece of software that manages groups of records which are related to one another.

Page 11: Relational Databases

11

Solution

Customers

CustID CustName CustAddress CustCity CustState CustPhone

Orders

OrdID OrdCustID OrdDate

OrderDetails

ODID ODOrdID ODDescription ODQty ODPrice

Page 12: Relational Databases

12

Advantages of a RDMS

All data is stored in the database Data redundancy is reduced Easier to maintain data integrity Eliminates the dependence between

programs and data. The database can operate as a stand

alone application.

Page 13: Relational Databases

13

Keys

A key is simply a field which can be used to identify a record.

Primary key A primary key is a field that uniquely

identifies a record in a table. No two records can have the same value

for a primary key.

Page 14: Relational Databases

14

Keys

Foreign Key A foreign key represents the value of

primary key for a related table. Foreign keys are the cornerstone of

relational databases.

Page 15: Relational Databases

15

Example

In the Customers Table, the CustID field will contain the data to uniquely identify a customer. This is the primary key.

In the Customers Table, the CustID field will contain the data to uniquely identify a customer. This is the primary key.

In the Orders table, the OrdCustID field would hold the value of the CustID field for the customer who placed the order. This makes OrdCustID a foreign key

In the Orders table, the OrdCustID field would hold the value of the CustID field for the customer who placed the order. This makes OrdCustID a foreign key

Page 16: Relational Databases

16

Solution

Customers CustID CustName CustAddress CustCity CustState CustPhone

Orders OrdID OrdCustID OrdDate

OrderDetails ODID ODOrdID ODDescription ODQty ODPrice

Primary Keys

Foreign KeysIn the Orders table, the OrdCustID field would hold the value of the CustID field for the customer who placed the order.

In the Orders table, the OrdCustID field would hold the value of the CustID field for the customer who placed the order.

Page 17: Relational Databases

17

Referential Integrity

This is a validity check a set of rules that avoids data inconsistency.

This means that a foreign key cannot be entered into one table unless it matches a primary key in another

Referential integrity can also prevent the deletion of a record if the record has a primary key that matches foreign keys in another table.