Next: Installed Types
Up: Data Types
Previous: Data Types
It is tempting to think that databases would be easier to use if only one data
type existed--a type that could hold any type of information, such as numbers,
character strings, or dates. Although a single data type would certainly make
table creation simpler, having different data types offers definite advantages:
- Consistent Results
- Columns of a uniform type produce consistent results. Displaying,
sorting, aggregates, and joins deliver consistent results. No conflict
arises over how different types are compared or displayed. For example, selecting
from an INTEGER column always yields INTEGER values.
- Data Validation
- Columns of a uniform type accept only properly formated data;
invalid data are rejected. For example, a column of type INTEGER will
reject a DATE value.
- Compact Storage
- Columns of a uniform type are stored more compactly.
- Performance
- Columns of a uniform type are processed more quickly.
For these reasons, each column in a relational database
can hold only one type of data. You cannot mix data types within a column.
This limitation can cause some difficulties. For example, our friend
table includes an age column of type INTEGER .
Only whole numbers can be placed in that column. The values ``I will ask for
his age soon'' or ``She will not tell me her age'' cannot be placed in that
column. NULL can represent ``I do not know her age.'' The solution
is to create an age_comments column of type CHAR()
to hold comments that cannot be placed in the age field.
Next: Installed Types
Up: Data Types
Previous: Data Types
Bruce Momjian
2001-05-09