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.
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".
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.
A characteristic of an entity or object. A detailed piece of information that describes an entity.
Each table is a separate and independent unit - although tables may be related
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.
storing the same information in more than one file.
E.g. a customers address stored in more than one file.
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.
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
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.
A relational database management system (RDBMS) is a piece of software that manages groups of records which are related to one another.
Eliminates the dependence between programs and data.
The database can operate as a stand alone application.
A key is simply a field which can be used to identify a record.
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.
A foreign key represents the value of primary key for a related table.
Foreign keys are the cornerstone of relational databases.
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
Solution Customers CustID CustName CustAddress CustCity CustState CustPhone Orders OrdID OrdCustID OrdDate OrderDetails ODID ODOrdID ODDescription ODQty ODPrice In the Orders table, the OrdCustID field would hold the value of the CustID field for the customer who placed the order. Primary Keys Foreign Keys
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.