Relational databases use data types such as integer, real/decimal, string, Boolean, and date/time to define what each field may store. Choosing the wrong type can cause invalid data, incorrect sorting or calculations, wasted storage, and reduced data integrity.
Data Types and Their Uses
A data type is assigned to each attribute during database design. The database management system (DBMS) uses it to determine valid values, permitted operations, storage requirements, and how values are compared.
| Data type | Appropriate use | Why the choice matters |
|---|---|---|
| Integer | Quantities, ages, counts | Supports exact whole-number calculations and numerical sorting. |
| Real/decimal | Measurements, prices, percentages | Stores values containing fractional parts. Decimal types are preferable where exact precision, such as currency, is required. |
| String/text | Names, addresses, telephone numbers, identification codes | Preserves characters, spaces, formatting, and leading zeros. |
| Boolean | Two-state values such as paid/unpaid | Restricts the field to two logical states, improving validation. |
| Date/time | Birth dates, deadlines, timestamps | Enables chronological sorting and date-based calculations. |
| Binary object | Images, audio, or other files | Stores non-text data, although databases may instead store a reference to an external file. |
The correct type depends on the field’s meaning, not just its appearance. For example, a telephone number may contain only digits, but it should normally be stored as text because it is not used in arithmetic and may begin with zero.
A common misconception is that any sequence of digits should use an integer type. If the identification code 00421 is stored as an integer, the leading zeros may be removed; if prices are stored as text, numerical sorting may place 100 before 20, and arithmetic cannot be performed directly.
IB Exam Technique
For A3.2 Database design, justify a type by linking it to the field’s purpose. In an exam response, name the type, explain the valid values or operations it supports, and state one consequence of an unsuitable choice, such as failed validation, inaccurate processing, or loss of data integrity.