unit 4 normalisationand relational database management systems
TRANSCRIPT
Unit 4Unit 4
NormalisationNormalisation
andand
Relational Database Relational Database
Management SystemsManagement Systems
Computerised Databases
A database is a organised collection of data items and links between them structured in such a way that it allows it to be accessed by a number of different application programs.
i.e. related tables of data which are linked together and many programs can use the data in the tables
Use a database when you need to store lots of data
Members No
Forename Surname Address 1 Address 2 Tel No Video No
122 Evans Daniel 7 High St Aberaeron 01545588999 343
759 Lees Anna 2 Bridge St
Lampeter 01570422967 523
122 Evans Daniel 7 High St Aberaeron 01545588999 455
Title Certificate Category Cost per day
Date loaned
Length of loan
Date due
Total cost
Crash 12 Comedy £3.00 12/09/05 1 day 13/09/05 £3.00
Emma 12 Drama £3.00 12/09/05 1 day 13/09/05 £3.00
War of the Worlds
PG Sci FI £3.59 14/09/05 2 days 16/09/05 £3.50
Duplication in Flatfile
Members Member number
Forename
Surname
Address line 1
Address line 2
Telephone number
Videos Video number
Title
Certificate
Category
Cost per day
Loans Member number
Video number
Date loaned
Length of loan
Date due
Total cost
Linked data tables in a relational database
Primary KeyForeign Key
Primary Key
Loans ID Primary Key
NormalisationNormalisation
Terminology: Primary KeyTerminology: Primary Key
A primary key is a A primary key is a unique valueunique value which allows which allows each record to be identifiedeach record to be identified
CustomerID FirstName LastName
1 Brian Smith
2 Harry Adams
3 Joe Jones
4 Harry Smith
FirstName or LastName cannot be primary keys as they contain duplicate and un-unique data. CustomerID uniquely identifies a row and is therefore suitable
Sometimes there is no single field appropriate Sometimes there is no single field appropriate as a primary key. In these circumstances, it as a primary key. In these circumstances, it is possible to select two fields which, when is possible to select two fields which, when taken together create a unique value:taken together create a unique value:
OrderNo ItemNo EmployeeNo CustomerNo ItemName Quantity
121 3 4 1024 Nut 4
121 4 4 1024 Bolt 3
122 8 9 176 Washer 6
123 3 6 154 Bolt 5
123 8 6 154 Washer 4
There are no unique fields, so the Primary Key is best suited by OrderNo and ItemNo taken together
Foreign KeyForeign Key
A Foreign key is a primary key of another A Foreign key is a primary key of another table used to link the tablestable used to link the tables
Second Normal Form (2NF)Second Normal Form (2NF)To be in 2NF a table must:To be in 2NF a table must:– Be in 1NF (obviously)Be in 1NF (obviously)– Have all non key fields fully functionally dependant on the Have all non key fields fully functionally dependant on the
primary keyprimary key
In English:In English:– A non key field is one that is not part of the primary keyA non key field is one that is not part of the primary key– It means that you need to use the primary key to determine It means that you need to use the primary key to determine
the value of the other fields in the tablethe value of the other fields in the table– If you can find the value of other fields without using the If you can find the value of other fields without using the
primary key, you should remove that field from the table and primary key, you should remove that field from the table and place it in a separate tableplace it in a separate table
Third Normal Form (3NF)Third Normal Form (3NF)To be in 3NF a table must:To be in 3NF a table must:
–Fields which do not form part of the Fields which do not form part of the primary key must always be solely primary key must always be solely dependent on the primary key and dependent on the primary key and not on anything else, such as not on anything else, such as another non key fieldanother non key field
Third Normal Form (Cont.)Third Normal Form (Cont.)
Remove City from the table and create a new cities tableRemove City from the table and create a new cities table
Remove Salary from the table and create a job type tableRemove Salary from the table and create a job type table
Staff
EmployeeID*
LastName
FirstName
CityID
TypeID
Cities
CityID*
City
JobTypes
TypeID*
Salary
WardID #WardID #
No of BedsNo of Beds
Type of Type of WardWard
DoctorIDDoctorID**
PatientID#PatientID#
NameName
IllnessIllness
GenderGender
AddressAddress
DoctorIDDoctorID**
WardIDWardID**
DoctorID#DoctorID#
WardIDWardID**NameName
SpecialismSpecialism
ContactNoContactNo
DoctorTable (DoctorID#, Name, Specialism, Contact No, WardID,)
WardTable (WardID#, No of Beds,Type of Ward, DoctorID)
PatientTable (PatientID#, Name,Adress, Illness, Gender, DoctorID, WardID)
,
# Primary Key
* Foreign Key
Advantages of using databasesAdvantages of using databases(Advantages of normalisation)(Advantages of normalisation)
1.1. Avoids data duplicationAvoids data duplication-data stored once-data stored once-linked by keyfields-linked by keyfields-all data available via relational links in keyfields-all data available via relational links in keyfields
2. Controlled redundancy2. Controlled redundancy - Minimises data duplication - Minimises data duplication
3. Ensures consistency3. Ensures consistency of dataof data - of data to all users- of data to all users
4. Data independence4. Data independence - data stored separately from programs so can add new - data stored separately from programs so can add new fields because data is independent of the applications fields because data is independent of the applications which use itwhich use it
5. Increased security5. Increased security
What makes databases secureWhat makes databases secure ? ?
Hierarchy of passwordsHierarchy of passwords
User access rights and privileges User access rights and privileges
Data is stored separately from programs Data is stored separately from programs so different programs cannot overwrite so different programs cannot overwrite data.data.
DisadvantagesDisadvantages
Complex to set up and maintain; needs team of Complex to set up and maintain; needs team of programmers to maintain it.programmers to maintain it.
Database software is large complex expensive Database software is large complex expensive and requires powerful computers.and requires powerful computers.
All applications which access the data will be All applications which access the data will be affected if database fails. As the DBMS is the affected if database fails. As the DBMS is the only access to operational data a system failure only access to operational data a system failure can have serious consequencescan have serious consequences