SQL Database Design For Developers at php[tek] 2024
What is Data? Types, Databases Explained
1.
2. WHAT IS DATA?
Data are all raw facts and figures. In simple words any number, letter or
symbol that can be entered into a computer system.
There are two main categories of data:
Digital data-data that is stored and manipulated on a computer.
Analogue data-data which is gathered without a computer.
3. DATA TYPES
The main types of data found in a computer system are:
1. Boolean/logical
2. Text/Alphanumeric
3. Numeric(numbers)
4. Currency(money)
5. Percentage
6. Date/time
4. BOOLEAN DATA
Boolean data can only have one of the two values. They are used when there
are only two possible responses to a question.
For example:
True/false
Yes/no
Male/female
1 or 0
Can any of you tell me one more example?
5. TEXT/ALPHANUMERIC
Text data:
Text data is used for data that is made up of letters only.
For example: a password using the word ‘EARTH’ would be regarded as text.
Alphanumeric data:
Alphanumeric data is used for data that is made up of letters and numbers.
for example: a password of ‘EARTH123’ would be regarded as alphanumeric.
7. NUMERIC DATA
Numeric(numbers) data can be in two forms:
1. Integer
2. Real
Integer Numbers:
• Integers are made up of whole numbers (numbers without decimals).
• Integers can be both positive and negative values.
For example:- the number 123 is an integer. -123 is also an integer.
Real Numbers:
• Real numbers are those that include decimals.
• Real numbers can be both positive (above zero) and negative (below zero).
For example:- the number 33.5 is a real number. -33.5 is also a real number.
9. CURRENCY NUMBERS
Currency numbers are real numbers (decimals) that have been formatted to
include money symbols ($, £ etc.)
Currency values that use decimals are usually shown to 2 decimal places.
For example:- £19.99 is a typical use of the currency value in England.
Currency values can be both positive (above zero) or negative (below zero).
10. PERCENTAGE NUMBERS
Percentage numbers are real numbers (decimals) that have been formatted
to show values out of 100. For example:
• 0.6 would become 60%
• 0.01 would become 1%
• 1.8 would become 180%
Percentage are usually shown with the percentage symbol (%).
Percentage values can be positive and negative.
11. DATE/TIME DATA
Date and Time data can be shown in many different ways. The most common
ways are shown in the table below:
12. DATABASE
A database is store of data that has been organized (sorted) in some way.
Database are so useful because they store data in a structured way and when
the data is structured (organized) it can be manipulated easily and then output
in different ways.
There are two types of database:
1. Flat-file database
2. Relational database
Database consists of the following:
1. Files/tables
2. Records
3. Fields
4. data
14. FILES/TABLES
A collection of records and fields is called a file.
Column headings are known as fields and one complete row is a full record
of data.
15. RECORDS
A database record shows all the data about one person or object.
One single row of a database table represents ONE record.
16. FIELD
Database fields hold/store the single items of data that make up a record.
Each cell of a table indicates a single field. A single field can hold one piece
of data.
Fields are given field names so we know what kind of data they hold. Field
names are found at the top of each column.
Fields are made up of 2 parts:-
So each record consists of eight fields.
17. KEY FIELD(UNIQUE DATA)
Key fields are individual pieces of data that are unique (only appear once).
They are used to differentiate one record from another.
Only the Patient Id is suitable for use as the unique key field.
19. FLAT-FILE DATABASE
Flat-File databases hold all of their data in one table only. They are only
suitable for very simple databases.
20. PROBLEMS USING A FLAT-FILE
DATABASE
The problems with using a flat-file databases are as follows:
Duplicated Data is often unnecessarily entered.
Database space is wasted with this duplicated data.
Duplicated Data takes a long time to enter and update (unnecessarily).
21. DATE REDUNDANCY
Data Redundancy is where you store the same data many times (duplicate
data) in your table.
This repeated data needs to be typed in over and over again which takes a
long time.
For example, the patients database contains several entries of duplicate data:
Doctor Id
Dr Hyde
Room 03
22. SOLUTION FOR DATE
REDUNDANCY
What is the solution to Data Redundancy?
The way to avoid the data redundancy problems that come with flat-file
databases is to create a relational database.
23. RELATIONAL DATABASE
Relational Databases use two or more tables linked together (to form a
relationship).
Relational Databases do not store all the data in the same table.
Repeated data is moved into it's own table as shown in the image below:
24. WHAT IS A RELATIONSHIP?
A relationship is formed when our two tables are joined together.
Relationships make use of key fields and primary keys to allow the two tables to
communicate with each other and share their data.
Key fields are identified using a primary key as shown in the image below:
Once the tables are linked together each one can read data from the other.
This means that we only need to enter the details of each doctor once instead of
many separate entries.
25. HOW DO YOU LINK THE TABLE?
In order to link the tables we need to use a common field.
A common field is data that appears in BOTH tables.
If you look at the image below you will see that the common field in the patient
database is Doctor Id:
At this stage you may have noticed the following: Doctor Table - The common
field (Doctor Id) is set as a key field
Patient Table - The common field is not set as a key field.
Common fields that are not being used as key fields are known as foreign keys.
26. FOREIGN KEY
A foreign key is a regular field in one table which is being used as the key field in
another table.
Foreign keys are used to provide the link (relationship) between the tables.
For example:-
In our patient database, Doctor Id is a key field in the Doctor Table but is also
being used in the Patient Table as a foreign key.
The foreign key (Doctor Id in the patient table) can then be used to match to the
primary key (Doctor Id in the doctor table) and share the correct data.
27. BENEFITS OF USING A RELATIONAL
DATABASE
The advantages of using a relational database instead of a
flat-file database are as follows: Duplicated Data is
reduced.
Database space is not wasted (due to unnecessary
duplicated data.
Quicker to enter Data as there are less duplicates.
Quicker to update Data
28. DIFFERENT TYPES OF DATA
1. Analogue data
Analogue data use values that change very smoothly.
A good example of this is an analogue clock. An analogue clock shows the time with a
smoothly moving seconds hand. The change is continuous.
Sound is also a good example of analogue data. Sound waves change in a very smooth
way.
29. ANALOGUE DEVICES
All analogue devices use analogue data. Examples of analogue devices
include:
Microphone
Headphones
Loud Speaker
Sensors (temperature, pressure etc.)
30. DIFFERENT TYPES OF DATA
2. Digital data
Digital data jumps from one value to the next in a step by step sequence.
A good example of this is a digital clock. A digital clock jumps from one second
to another in clear steps. The change is not smooth or continuous.
Digital devices
All digital devices use digital data. Examples of digital devices include:
Computers/Laptops/IPads
Mobile Phone
MP3 Player
Digital Camera
The name "Digital" is given to all devices that store and process data in the form
of 'digits' (numbers). These digits are known as 'Binary'.
31. BINARY
All computer data is really a number known as a Binary Digit (often shortened
to just binary). Binary is represented by the numbers 1 and 0.
Different combinations of these 1's and 0's are used to represent all the different
kinds of data that can be stored and processed within a digital device (such as a
computer).
For example:-
The word 'Hello' is stored as the binary combination of
0100100001100101011011000110110001101111
32. ANALOGUE AND DIGITAL
CONVERSION
Analogue values can only be used by analogue devices. Digital values can only
be used by digital devices.
If we want to use analogue values with a digital device or digital values
with an analogue device we need to use data conversion.
There are two types of data converters:
1. Analogue to Digital Converter (ADC)
2. Digital to Analogue Converter (DAC)
33. ANALOGUE TO DIGITAL CONVERTER (ADC)
If we try to attach an analogue device (like a microphone) to a computer we
will need to convert the analogue data to digital before the computer can
use it.
The microphone is used to pass the analogue sound waves through the ADC
which will convert the sound from analogue to digital.
The ADC then passes the converted digital data into the computer where the
sound can be stored and edited.
34. DIGITAL TO ANALOGUE CONVERTER
(DAC)
If we want to listen to digital music (like mp3's) we would need to attach an
analogue device such as loud speakers or headphones to our computer.
The computer will pass the digital sound values through a DAC (located on a
sound card) which will convert the digital data to analogue.
The DAC then passes the converted analogue data onto the analogue loud
speaker which we would then hear as sound waves.
35. TEMPERATURE CONTROL IN
GREENHOUSE
Imagine we had a greenhouse and we wanted a way to control the temperature
inside automatically. We could do this using a range of analogue and digital
devices and ADC's/DAC's to convert all of the data.
This is how it would work:
1. Analogue thermometer is used to gather smoothly changing temperature
data.
2. Analogue data is converted to digital using a ADC and fed into a digital
computer.
3. Computer reads the digital data and decides if the temperature is too hot or
too cold.
4. Computer sends data to a DAC built into a heater with 1 of 2 instructions:
If the temperature is too hot, the heater will be turned off.
If the temperature is too cold the heater will be turned on.
37. QUESTIONS!!!
1. Numeric data can be in two forms integer or ………………
2. Letters and numbers together are called ……………………… data.
3. Logical or ……………………. data can have only one of the two values: true or
false.
4. A record consists of many …………………
5. A database where the data is held in two or more tables with links established
between them is called a ………………….. database.
6. An analogue signal from a temperature sensor will nee to be converted into a
……………... signal before it can be processed by a computer.
7. Changing from an analogue to a digital signal is performed using an
…………………… converter.