Lecture 8 Introduction To Databases (Updated)
Lecture 8 Introduction To Databases (Updated)
W eeks 6 & 7 IS D A gile and S crum Final exam only V LO O K U P, C O N C AT, IF, A ssignm ent 2
LE FT, R IG H T etc.
W eek 8 D atabases (tables, D B M S ) Final exam only V LO O K U P, X LO O K U P, A ssignm ent 2 and
U N IQ U E , S O RT, Final exam
FILTE R .
W eek 9 D atabase E R D s, m ore database rules Final exam only U N IQ U E , S O RT, A ssignm ent 2 and
FILTE R , R E P LA C E Final exam
W eek 10 D atabases dem onstration Final exam only G oal S eek Final exam only
W eek 11 B usiness intelligence (data w arehouses, Final exam only S olver Final exam only
types of B I)
W eek 12 B usiness intelligence (M L, A I) Final exam only S olver Final exam only
Learning objectives
• W hat is a database, and how does a relational database organise data?
• W hat are the characteristics of a relational database and how to structure one?
• W hat are the principles of a database management system?
• W hat are the principal tools and technologies for accessing information from databases to improve
business performance and decision making?
1
14/4/2025
Databases
Databases
Cust ID Cust name Agent ID Agent name Order ID Order date Toy ID Toy name Toy unit price Quantity Total price
1 Sherry Don CB Cat Bon 001 6/04/22 DA Drone A $ 500.00 1 $1,250
1 Sherry Don CB Cat Bon 001 6/04/22 LA Lego Architect $ 750.00 1 $1,250
2 Jack Bickleben KR Kevin Row 002 7/04/22 BMWM BMW Motorbike $ 500.00 1 $500
3 Jules Bicep SC Sam Curl 003 7/04/22 RH Rocking Horse $ 1,000.00 2 $2,000
4 Liam Hamsbor DK Daisy Kot 004 08/04/22 TB Teddy Bear $ 750.00 1 $2,750
4 Liam Hamsbor DK Daisy Kot 004 08/04/22 DB Drone Bmax $ 1,000.00 2 $2,750
5 Maria Barry DB David Bham 005 08/04/22 DH Doll House $ 2,000.00 1 $2,000.00
Databases
Cust ID Cust name Agent ID Agent name Order ID Order date Toy ID Toy name Toy unit price Quantity Total price
1 Sherry Don CB Cat Bon 001 6/04/22 DA Drone A $ 500.00 1 $1,250
1 Sherry Don CB Cat Bon 001 6/04/22 LA Lego Architect $ 750.00 1 $1,250
2 Jack Bickleben KR Kevin Row 002 7/04/22 BMWM BMW Motorbike $ 500.00 1 $500
3 Jules Bicep SC Sam Curl 003 7/04/22 RH Rocking Horse $ 1,000.00 2 $2,000
4 Liam Hamsbor DK Daisy Kot 004 08/04/22 TB Teddy Bear $ 750.00 1 $2,750
4 Liam Hamsbor DK Daisy Kot 004 08/04/22 DB Drone Bmax $ 1,000.00 2 $2,750
5 Maria Barry DB David Bham 005 08/04/22 DH Doll House $ 2,000.00 1 $2,000.00
1 Sherry Don CB Cat Bon 001 6/04/23 DA Drone A $ 500.00 1 $1,250
1 Sherry Don CB Cat Bon 001 6/04/23 LA Lego Architect $ 750.00 1 $1,250
2 Jack Bickleben KR Kevin Row 002 7/4/23 BMWM BMW Motorbike $ 500.00 1 $500
3 Jules Bicep SC Sam Curl 003 7/4/23 RH Rocking Horse $ 1,000.00 2 $2,000
4 Liam Hamsbor DK Daisy Kot 004 8/4/23 TB Teddy Bear $ 750.00 1 $2,750
4 Liam Hamsbor DK Daisy Kot 004 8/4/24 DB Drone Bmax $ 1,000.00 2 $2,750
5 Maria Barry DB David Bham 005 08/04/23 DH Doll House $ 2,000.00 1 $2,000.00
1 Sherry Don CB Cat Bon 001 6/04/23 DA Drone A $ 500.00 1 6
$1,250
1 Sherry Don CB Cat Bon 001 6/04/23 LA Lego Architect $ 750.00 1 $1,250
2 Jack Bickleben KR Kevin Row 002 7/04/23 BMWM BMW Motorbike $ 500.00 1 $500
3 Jules Bicep SC Sam Curl 003 7/04/23 RH Rocking Horse $ 1,000.00 2 $2,000
6
4 Liam Hamsbor DK Daisy Kot 004 7/04/23 TB Teddy Bear $ 750.00 1 $2,750
4 Liam Hamsbor DK Daisy Kot 004 7/04/23 DB Drone Bmax $ 1,000.00 2 $2,750
5 Maria Barry DB David Bham 005 6/04/23 DH Doll House $ 2,000.00 1 $2,000.00
1 Sherry Don CB Cat Bon 001 6/04/23 DA Drone A $ 500.00 1 $1,250
1 Sherry Don CB Cat Bon 001 8/4/24 LA Lego Architect $ 750.00 1 $1,250
2 Jack Bickleben KR Kevin Row 002 8/4/24 BMWM BMW Motorbike $ 500.00 1 $500
3 Jules Bicep SC Sam Curl 003 8/4/24 RH Rocking Horse $ 1,000.00 2 $2,000
4 Liam Hamsbor DK Daisy Kot 004 7/04/23 TB Teddy Bear $ 750.00 1 $2,750
4 Liam Hamsbor DK Daisy Kot 004 7/04/23 DB Drone Bmax $ 1,000.00 2 $2,750
5 Maria Barry DB David Bham 005 7/04/23 DH Doll House $ 2,000.00 1 $2,000.00
2
14/4/2025
Databases
(Mallach 2016)
7
Databases
What is a database?
• A collection of data organised to service many applications at the same time by
storing and managing data so that they appear to be in one location
• Data represented as one or more two-dimensional tables with columns and rows
Databases
3
14/4/2025
10
Databases
11
11
Databases
Imagine the power of a query like: show me persons aged under 25, that live in Australia, that like
running à to provide running shoe advertising to.
(Mallach 2016)
12
12
4
14/4/2025
Databases
Shaz
13
13
Databases
14
Databases
Relational databases
Work with large amounts of data efficiently, make updating data easy and reliable and ensure
accuracy, data security and avoiding redundancy
15
15
5
14/4/2025
Databases
Relational databases
Work with large amounts of data efficiently, make updating data easy and reliable and ensure
accuracy, data security and avoiding redundancy
• One Table for each Entity:
E.g., CUSTOMER, SALES, AGENT, STOCK, SUPPLIER, etc
Fields (Columns) store data representing an Attributes of an Entity
Rows store data for separate records of instances of an entity
16
16
Databases
Relational databases
Entity: is anything of interest to the users of the database. An entity is a person, place, thing or event to be
recorded in the database. Entities will almost always occur as the nouns, or naming words, in the user’s
description of their work e.g. in a university environment, a user may speak of students, courses, lecturers,
and degrees. They are not an instance (e.g. an individual person).
Attribute: a specific characteristic or quality of a particular entity e.g. for a table on “Students”,
characteristics would include student_name and student_address to distinguish one instance of a student
from another we give them a different name, address, and so on.
Record: a group of related fields (e.g. a row) for an instance of entity
Field: A field describe some detail or characteristic of a record (e.g. a single cell).
17
17
Databases
Relational databases
Example: Customer Table
• Entity: Customer
• Attributes: Customer name, Customer Address, Customer Phone number, Loyalty Level
• Records or Instances example; Sherry Don, from address xxxxxxxaaaa, with phone number (00)12234323 is
in Red tier of loyalty program
18
18
6
14/4/2025
Databases
Relational databases
Example: Customer Table
• Entity: Customer
• Attributes: Customer name, Customer Address, Customer Phone number, Loyalty Level
• Records of Instances example; Customer #1, Sherry Don, from address xxxxxxxaaaa, with phone number
(00)12234323 is in Red tier of loyalty program
Unique value
Cust ID Cust name Cust Address Cust Phone # Loyalty level
1 Sherry Don xxxxxxxaaaa (00)12234323 Red
2 Jack Bickleben xxxxxxxbbbb (00)23336543 Blue
3 Jules Bicep xxxxxxcccc (00)35534323 Silver
4 Liam Hamsbor xxxxxxxdddd (00)12234352 Gold
5 Maria Barry xxxxxxxdddd (00)12263098 Gold
6 Sherry Don yyyyyyydddd (01)12745695 Blue
• Unique value can also be used as KEYS
• KEYS refer to only one specific row or record
19
19
Databases
Relational databases
Examples: Toy_Price Table, Order_Price Table
• Entity: Customer
• Attributes: Customer name, Customer Address, Customer Phone number, Loyalty Level
• Records of Instances example; Customer #1, Sherry Don, from address xxxxxxxaaaa, with phone number
(00)12234323 is in Red tier of loyalty program
Unique value
Unique value
Toy ID Toy name Toy unit price Order ID Order date Total price
DA Drone A $ 500.00 001 6/04/22 $1,250
LA Lego Architect $ 750.00 002 7/04/22 $500
BMWM BMW Motorbike $ 500.00 003 7/04/22 $2,000
RH Rocking Horse $ 1,000.00 004 08/04/22 $2,750
TB Teddy Bear $ 750.00 005 08/04/22 $2,000.00
DB Drone Bmax $ 1,000.00
DH Doll House $ 2,000.00
20
Databases
21
21
7
14/4/2025
Databases
22
22
Databases
24
24
Databases
Cust ID Cust name Cust Address Cust Phone # Loyalty level Toy ID Toy name Toy unit price
1 Sherry Don xxxxxxxaaaa (00)12234323 Red DA Drone A $ 500.00
2 Jack Bickleben xxxxxxxbbbb (00)23336543 Blue LA Lego Architect $ 750.00
BMWM BMW Motorbike $ 500.00
3 Jules Bicep xxxxxxcccc (00)35534323 Silver
RH Rocking Horse $ 1,000.00
4 Liam Hamsbor xxxxxxxdddd (00)12234352 Gold TB Teddy Bear $ 750.00
5 Maria Barry xxxxxxxdddd (00)12263098 Gold DB Drone Bmax $ 1,000.00
6 Sherry Don yyyyyyydddd (01)12745695 Blue DH Doll House $ 2,000.00
Agent ID Agent name Average Daily Sales in April Order ID Order date Total price
CB Cat Bon $5,000.00 001 6/04/22 $1,250
KR Kevin Row $2,500.00 002 7/04/22 $500
SC Sam Curl $7,000.00 003 7/04/22 $2,000
004 08/04/22 $2,750
DK Daisy Kot $3,000.00
005 08/04/22 $2,000.00
DB David Bham $4,000.00
Query examples:
Select toys that have been customers’ favourite toy in 2022
Find agents with highest order values for top tier customers
25
25
8
14/4/2025
Databases
Toy ID Toy name Toy unit price Cust ID Cust name Cust Address Cust Phone # Loyalty level Favourite Toys
DA Drone A $ 500.00 1 Sherry Don xxxxxxxaaaa (00)12234323 Red DA
LA Lego Architect $ 750.00 2 Jack Bickleben xxxxxxxbbbb (00)23336543 Blue DA
BMWM BMW Motorbike $ 500.00 3 Jules Bicep xxxxxxcccc (00)35534323 Silver BMWM
RH Rocking Horse $ 1,000.00
4 Liam Hamsbor xxxxxxxdddd (00)12234352 Gold RH
TB Teddy Bear $ 750.00
DB Drone Bmax $ 1,000.00 5 Maria Barry xxxxxxxdddd (00)12263098 Gold RH
DH Doll House $ 2,000.00 6 Sherry Don yyyyyyydddd (01)12745695 Blue DB
Primary Key One toy can be multiple customers’ favourite toy Foreign Key
26
26
Databases
27
27
Databases
28
28
9
14/4/2025
[E n tity N a m e ]
29
Databases
Relational databases: Model characteristics
Email Table
Student
EmailNum Date Message Number
1 2/01/2008 For homework 1, do you want us to provide notes on our references? 1325
2 3/15/2008 My group consists of Swee Lau and Stuart Nelson 1325
3 3/15/2008 Could you please assign me to a group? 1644 • Three tables “Email”, “Student”, and
“Office_Visit”.
Student Table
Student
Student Name HW1 HW2 MidTerm • Each table contains one or more
Number
1325 BAKER, ANDREA 88 100 78
records – these are the rows of each
1644 LAU, SWEE 75 90 90 table.
2881 NELSON, STUART 100 90 98
3007 FISCHER, MAYAN 95 100 74
• Each record or row contains one or
3559 TAM, JEFFREY 88 100 88 more fields, or characteristics or
4867 VERBERRA, ADAM 70 90 92 attributes (row/record mean the same
5265 VALDEX, MARIE 80 90 85 thing in the context of a relational
8009 ROGERS, SHELLY 95 100 98
database).
Office_Visit Table • The overall database comprises 3
Student tables with attributes and records
VisitID Date Notes Number
2 2/13/2008 Andrea had questions about using IS for raising barriers to entry 1325
3 2/17/2008 Jeffrey is considering his IS major. Wanted to talk about career opportunities 3559
4 2/17/2008 Will miss class Friday due to job conflict 4867
30
30
Databases
S tu d e n t T a b le
S tu d e n t
S tu d e n t N a m e HW 1 HW 2 M id T e rm
N um ber
1325 BAKER, AN DREA 88 100 78
P rim ary key 1644 LAU , SW EE 75 90 90 Foreign key
2881 N ELSO N , STU ART 100 90 98
3007 F IS C H E R , M A Y A N 95 100 74
3559 T A M , JE F F R E Y 88 100 88
4867 VERBERRA, ADAM 70 90 92
5265 V A L D E X , M A R IE 80 90 85
8009 RO G ERS, SH ELLY 95 100 98
O ffice _ V isit T a b le
Student
V isitID D a te N o te s
Number
2 2 /1 3 /2 0 0 8 A n d re a h a d q u e stio n s a b o u t u sin g IS fo r ra isin g b a rrie rs to e n try 1325
3 2 /1 7 /2 0 0 8 Je ffre y is c o n sid e rin g h is IS m a jo r. W a n te d to ta lk a b o u t c a re e r o p p o rtu n itie s 3559
4 2 /1 7 /2 0 0 8 W ill m iss c la ss F rid a y d u e to jo b c o n flic t 4867
31
31
10
14/4/2025
[E n tity N a m e ]
32
Databases
33
Databases
Normalization in databases
• Normalization is a method for analysing and reducing a relational database to its most streamlined form
to ensure minimum redundancy, maximum data integrity and optimal processing performance.
• The process of streamlining complex groups of data to minimize redundant data elements and awkward
many-to-many relationships and increase stability and flexibility is called normalisation.
• A properly designed and normalised databased is easy to maintain and minimizes duplicate data.
• Relational database systems enforce referential integrity rules to ensure that relationships between
coupled tables remain consistent.
34
34
11
14/4/2025
Databases
Normalization
Normalization is a process that aims at achieving better designed relational database schemas using
• Functional Dependencies
• Primary Keys
The normalization process takes a relational schema through a series of tests to certify whether it satisfies
certain conditions
• The schemas that satisfy certain conditions are said to be in a given Normal Form
• Unsatisfactory schemas are decomposed by breaking up their attributes into smaller relations that
possess desirable properties (e.g., no anomalies)
In short
W hat – Removing Redundancies and Anomalies
How – Identifying Dependencies and breaking up tables until no anomalies exist
35
35
Databases
Normalization - Overview
1NF 3NF
• Outcome: Identifying non-atomic values from • Outcome: Identifying partial and transitive
relations. dependencies, which helps remove most
• Test: Relation should have no multivalued anomalies
attributes or nested relations. • Test: LHS of any non-trivial FD in F+ is a
superkey, or RHS is a prime attribute.
2NF BCNF
• Outcome: Identifying partial dependencies, • Outcome: Identifying all anomalies at the cost
which helps remove some anomalies. of not preserving all FDs
• Test: LHS of any non-trivial FD in F+ is not a • Test: LHS of any non-trivial FD in F+ is a
proper subset of a candidate key, or RHS is a superkey.
prime attribute
36
Databases
• Outcome: No repeating groups of data. • Outcome: Any potential secondary keys have
• Test: Data is defined by Primary Key(s). There been removed.
are no repeating of the Key. Each cell contains • Test: No Transitive Dependencies – there is a
only ONE value non-key attribute that can define some of the
other non-key attributes
37
12
14/4/2025
Databases: Normalization
Example: Student & Lecturer database
Student ID Student Name Course ID Grade Lecturer Lecturer
Address
S01 Max C01 78 Dr Brown St Lucia, 4067
S02 Jack C02 82 Dr Green Taringa, 4069
S03 Julie C03 67 Dr Peter Toowong, 4068
S04 Jane C04 89 Prof. Clark Indooroopilly,
4069
39
Databases: Normalization
1st Normalisation Form
• There are no repeating groups. • There are no repeating of the Key.
• Data is defined by Primary Key(s). • Each cell contains only ONE value
40
Databases: Normalization
1st Normalisation Form
• There are no repeating groups.
• Data is defined by Primary Key(s).
• There are no repeating of the Key.
• Each cell contains only ONE value
2 nd Normalisation Form
• Outcome: All non-key attributes are fully
dependant on its Primary Key.
• Test: No Partial Dependencies – there is a
composite key, and some data only needs one
part of it.
41
41
13
14/4/2025
Databases: Normalization
2nd Normalisation Form
Student ID Student Name Course ID Lecturer Student ID Course ID Grade
S01 Max C01 Dr Brown S01 C01 78
S02 Jack C02 Dr Green S02 C02 82
S03 Julie C03 Dr Peter S03 C03 67
S04 Jane C04 Prof. Clark S04 C04 89
42
Databases: Normalization
2nd Normalisation Form
3 rd Normalisation Form
• Outcome: Any potential secondary keys have
been removed.
• Test: No Transitive Dependencies – there is a
non-key attribute that can define some of the
other non-key attributes
43
43
Databases: Normalization
3rd Normalisation Form
Student ID Student Name Course ID Lecturer Student ID Course ID Grade
S01 Max C01 Dr Brown S01 C01 78
S02 Jack C02 Dr Green S02 C02 82
S03 Julie C03 Dr Peter S03 C03 67
S04 Jane C04 Prof. Clark S04 C04 89
44
14
14/4/2025
Databases: Normalization
3rd Normalisation Form
45
45
[E n tity N a m e ]
46
[E n tity N a m e ]
47
15
14/4/2025
[E n tity N a m e ]
48
Databases: Normalization
Discussion question
Student Bike-Commuter table
Student_id Student_name
245 Bob Smith
265 Xi Wang
987 Anthony Marshall
The database table structure above captures Students that commute to the University by bike. Each
student is assigned one Bike Storage Building where they can store their bike and access facilities like
change rooms and a locker. A Bike Storage Building can have many students.
What is the most appropriate Foreign Key and where should we place the Foreign Key in this table
structure so that we can link the two tables?
49
49
50
50
16
14/4/2025
51
51
DBMS
• For a user to communicate or talk to the database, both the database and the user must speak the
same language.
• To make this exchange practical in a world where there are thousands of software vendors, and also a
large number of relational database builders, the overall industry has agreed on a standardised
database language.
• This means that we have a standardised language that all databases should implement, and that all
software applications should use.
• This language is called Structured Query Language or, SQL. This language is also the reason for data
independence, that is, we can design software applications without concerning ourselves as to the
internal design details of a relational database.
• For instance, the query: SELECT NAME, EMAIL FROM STUDENT W HERE COURSE = “BISM1201”
AND GRADE IS => B
• Would list all the students taking BISM1201 with a grade higher than a B
52
52
53
53
17
14/4/2025
54
Join:
• Combines relational tables to present the server with more information than is available from individual
tables
Project (display):
• Creates a subset consisting of columns in a table
55
55
56
56
18
14/4/2025
• Data dictionary:
- An automated or manual file that stores definitions and data elements and their characteristics. MS
Access example captures name, description, size, type, format and other properties. (See example on
page 229).
57
57
Example of an S Q L Query
SELECT PART.Part_Number, PART.Part_Name, SUPPLIER.Supplier_Number,
SUPPLIER.Supplier_Name
FROM PART, SUPPLIER
WHERE PART.Suplier_Number = SUPPLIER.Supplier_Number
AND (Part_Number = 137 OR Part_Number = 150);
This query displays Part number, part name, supplier number and supplier name from the PART and SUPPLIER
table, where the there is a match between the supplier number and the Part 137 or Part 150.
58
An Access Query
59
59
19
14/4/2025
60
60
Non-relational databases
• “NoSQL”
• Handle large data sets of data that are not easily organized into tables,
columns, and rows
• Use more flexible data model
- Don’t require extensive structuring
• Can manage unstructured data, such as social media and graphics
• E.g. Amazon’s Simple D B, MetLife’s Mongo D B
61
61
62
62
20
14/4/2025
Blockchain
• Distributed database of transactions
63
63
Each accountant rushes to be the first to check whether you can afford it (and be paid their salary "Bitcoins"). The first to check and validate hits “REPLY ALL”,
attaching their logic for verifying the transaction ("proof of work"). If the other accountant agrees, everyone updates their file…
64
64
65
65
21
14/4/2025
66
• There is no additional reading for next week. (It is the same as this week)
67
67
B IS M 1 2 0 1 T ra n s fo rm in g B u s in e s s w ith In fo rm a tio n S y s te m s
• W hat are the characteristics of a relational database and how to structure one?
• W hat are the principles of a database management system?
• W hat are the principal tools and technologies for accessing information from databases to improve
business performance and decision making?
68
68
22
14/4/2025
facebook.com /uniofqld
69
23