relational databases
Post on 21-Jul-2016
9 Views
Preview:
DESCRIPTION
TRANSCRIPT
1
Introduction to Relational Databases 1
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.
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".
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.
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
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.
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.
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.
A company which takes orders from many
customers
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.
10
Solution A relational database management
system (RDBMS) is a piece of software that manages groups of records which are related to one another.
11
Solution
Customers CustID CustName CustAddress CustCity CustState CustPhone
Orders OrdID OrdCustID OrdDate
OrderDetails ODID ODOrdID ODDescription ODQty ODPrice
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.
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.
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.
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 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
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.
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.
top related