Different Data Types Used in Relational Databases
String Data Types
- CHAR(size)
- Description: Fixed-length string.
- Example: CHAR(6) for storing a fixed-length ID like P@ssWd.
- VARCHAR(size)
- Description: Variable-length string.
- Example: VARCHAR(255) for names or email addresses.
- TEXT
- Description: Large text field, up to 65,535 characters.
- Example: Storing product descriptions.
- ENUM
- Description: String field with predefined values.
- Example: ENUM('Male', 'Female', 'Other') for gender.
- SET
- Description: String field that can hold multiple values from a predefined list.
- Example: SET('Reading', 'Traveling', 'Sports') for hobbies.
String data types are ideal for storing textual information, but they cannot be used for numerical calculations or date comparisons.
Numeric Data Types
- INT
- Description: Whole numbers.
- Example: INT for storing quantities or IDs.
- FLOAT(p)
- Description: Floating-point numbers.
- Example: FLOAT(7,2) for storing prices like 19.99.
- BOOL
- Description: Boolean values (0 for false, 1 for true).
- Example: BOOL for flags like isActive.
- BIT (SIZE)
- Description: Stores binary values from 1 - 64 bits in size
- Example: BIT (4) to store the number 3: 0011
Numeric data types are essential for calculations, but using them for non-numeric data (e.g., phone numbers) can lead to errors.
Date/Time Data Types
- DATE
- Description: Stores dates in YYYY-MM-DD format.
- Example: DATE for birthdates.
- DATETIME
- Description: Stores date and time in YYYY-MM-DD hh:mm:ss format.