Organisation methods 2: Relational Databases
-
Upload
rosaline-yroz -
Category
Documents
-
view
17 -
download
1
description
Transcript of Organisation methods 2: Relational Databases
CORE 2: Information systems and Databases
ORGANISATION METHODS 2:RELATIONAL DATABASES
A relational database is a collection of tables that are linked so that changes in relative data can be processed throughout all entities. The actual tables themselves maintain the same internal structure as flat-fi le databases, using attributes and records to display information. However the way that they are linked follows a few unique structures that may be more eff ective at organising information in diff erent situations. These relational structures are: one to one, one to many, and many to many.
RELATIONAL DATABASES
This is managed by an RDBMS – Relational Database Management software.
An RDBMS initiates Information Processes on the linked tables as well as processes that create and modify the design of the tables themselves.
RELATIONAL DATABASES
There are some key concepts to grasp in the organization of relational databases….
TABLESPRIMARY KEYSRELATIONSHIPSREFERENTIAL INTEGRITY
LOGICAL ORGANIZATION OF RELATIONAL DATABASES
TABLESThe basic building block of all relational databases is the table.Few things about ‘tables’…
Each table is a set of rows (records) and columns (fields)
A single table is like a flat fi le databaseRecords can be called tuples and fields attributesTables are called entities and each row or record
describes all of the data about a particular entityEach record is unique, there are never two identical
records
LOGICAL ORGANIZATION OF RELATIONAL DATABASES
PRIMARY KEYSEvery Table within a relational database must have a Primary Key which is a field or combination of fields that uniquely identifies each record.
The Primary Key is either a single field or a combination of fields (a Composite key)
It is typically a single integer fieldMust be uniqueA Primary Key is joined to a Foreign Key in another
table
LOGICAL ORGANIZATION OF RELATIONAL DATABASES
RELATIONSHIPS Tables are linked together via relationships. A relationship creates a join between the primary key in one table and the foreign key in another. We model these relationships uisng a SCHEMA or ERD (Entity Relationship Diagram) that looks like this…
LOGICAL ORGANIZATION OF RELATIONAL DATABASES
Or this…
LOGICAL ORGANIZATION OF RELATIONAL DATABASES
RELATIONSHIPS CONTD…
Database Schemas or schematic diagrams model relationships with a relational database and include each entity (table) together with its attributes (fields). The primary key is underlined. Lines between attributes represent the relationships and each line is labeled to identify the nature of the join.
Foreign Keys are fields that must contain data that matches the Primary Key of another table. Hence datat ypes MUST match between PK’s and FK’s.
LOGICAL ORGANIZATION OF RELATIONAL DATABASES
RELATIONSHIPS CONTD…
There are three types of Relationships…
ONE to MANY (1:M)ONE to ONE (1:1)MANY to MANY (M:M)
LOGICAL ORGANIZATION OF RELATIONAL DATABASES
RELATIONSHIPS CONTD…
ONE to MANY (1:M)
One to Many is by far the most common relationship and what it means is that for each record in the PK’s table, there can be multiple records in the FK’s table.
Eg. One Customer can have many products OR one Borrower can have many loans
LOGICAL ORGANIZATION OF RELATIONAL DATABASES
RELATIONSHIPS CONTD…
ONE to ONE (1:1)
One to One relationships are seldom required however there are occasions where they may be included in a DB to improve performance or reduce storage.
Eg. One ‘Offi ce_Worker’can have one ‘Offi ce’ and therefore the relationship can reflect this.
LOGICAL ORGANIZATION OF RELATIONAL DATABASES
RELATIONSHIPS CONTD…
MANY to MANY (M:M)
Many to Many relationships must always be resolved by creating a join table with two 1:M relationships. For example Many ‘Customers’ can have many ‘Loans’ but in reality this is impossible to create using our DBMS. To resolve this where ever we fi nd a need for a M:M we replace it with two 1:M and a join table like a ‘Transaction’ table.
Come to page 132, 133 of your text for further explanation.
LOGICAL ORGANIZATION OF RELATIONAL DATABASES
REFERENTIAL INTEGRITYReferential integrity refers to when tables are synchronised so that data changes carry over all tables. It is ensured when each FK always matches a related PK.
When a Primary Key is updated then changes must be reflected throughout all tables (MS ACCESS call this ‘Cascade Update Related Fields’)
If a Primary Key is deleted then the orphaned FK’s need to be deleted also (MS ACCESS calls this ‘Cascade Delete Related Fields’)
LOGICAL ORGANIZATION OF RELATIONAL DATABASES