A3.2.3
Outline the different data types used in relational databases
Common relational database data types can be grouped into: string data types numeric data types date/time data types
- Common relational database data types can be grouped into:
- string data types
- numeric data types
- date/time data types
String data types
CHAR- fixed length
- the length is defined explicitly, for example
CHAR(7) - if the inserted value is shorter, spaces may be used to pad it
- suitable for fixed-length values such as:
- IDs
- passwords
- country codes
- status flags
VARCHAR- variable length
- suitable for:
- names
- emails
- descriptions
TEXT- used for longer text such as:
- blog posts
- articles
- comments
- product reviews
- used for longer text such as:
MEDIUMTEXT- used for larger text such as:
- long documentation
- large JSON data
- novels or books
- used for larger text such as:
LONGTEXT- used for extremely large text such as:
- large archives
- very large documentation
- full codebases
- used for extremely large text such as:
ENUM- one value must be chosen from a predefined list
- suitable for:
- status fields
- user roles
- categories with exactly one allowed choice
SET- zero or more values can be chosen from a predefined list
- suitable for:
- user interests
- multiple skills
- multiple tags or categories
Numeric data types
BIT- stores bit-field values where each bit is
0or1 - suitable for:
- boolean values
- on/off states
- permission flags
- stores bit-field values where each bit is
BOOL/BOOLEAN- stores true/false style values
- suitable for:
- toggle settings
- status indicators
INT- stores whole numbers
- suitable for:
- primary keys
- foreign keys
- counts
- quantities
FLOAT- stores approximate decimal numbers
- suitable when exact precision is less important
DECIMAL(a,b)- stores exact decimal numbers with fixed precision
ais the total number of digitsbis the number of digits after the decimal point- suitable for:
- money
- measured values where exact precision matters
Date/time data types
DATE- stores a calendar date
TIME- stores a time
DATETIME/TIMESTAMP- stores both date and time