What is the main purpose of data types in SQL?
To control what kind of data is allowed in each column.
Data types ensure data integrity and proper storage.
What do data types prevent?
Nonsense data like “19.99 bananas” entering your table.
This helps maintain the accuracy of the database.
Why are data types important for sorting and filtering?
Sorting only works correctly when types are correct (e.g., number vs text).
Incorrect types can lead to unexpected results.
What happens if data types are too large (e.g., VARCHAR(5000))?
Slow queries and wasted storage.
Efficient data types improve performance.
What’s the correct type for storing book titles?
VARCHAR or NVARCHAR.
Use VARCHAR for standard text and NVARCHAR for international characters.
What’s the correct data type for a published date?
DATE.
DATE type is specifically designed for date values.
What data type should store price values?
DECIMAL(precision, scale).
DECIMAL ensures exact representation of monetary values.
What data type should store “active/not active”?
BIT.
BIT is efficient for binary states.
What is TINYINT used for?
Small counts (0–255), ratings, flags.
TINYINT is a space-efficient integer type.
What is SMALLINT used for?
Counts up to ~32,000 (stock levels, medium inventory).
SMALLINT is suitable for moderate range integer values.
What is INT used for?
Most general whole number tasks (IDs, counts).
INT is the standard integer type in SQL.
What is BIGINT used for?
Very large numbers — only when truly necessary.
Use BIGINT for values exceeding INT limits.
What is DECIMAL used for?
Precise numbers like prices or money.
DECIMAL avoids rounding errors common in floating-point types.
Why is DECIMAL better than FLOAT for money?
FLOAT causes rounding errors; DECIMAL is exact.
Financial calculations require precision.
What is FLOAT used for?
Scientific values, measurements, coordinates.
FLOAT is suitable for approximate values.
Should FLOAT be used for money?
No — rounding is unreliable.
Use DECIMAL for financial data instead.
When should you use DATE?
Birthdays, published dates, simple dates.
DATE type is ideal for storing date values.
When should you use DATETIME?
Timestamps with hours/minutes/seconds.
DATETIME captures both date and time.
What is TIME used for?
Storing only the time of day.
TIME type is focused solely on time values.
When should you use VARCHAR?
Normal English text; lightweight and efficient.
VARCHAR is flexible for variable-length strings.
When should you use NVARCHAR?
Any user input; supports accents and international characters.
NVARCHAR is essential for multilingual applications.
Why is NVARCHAR safer?
It handles all human languages reliably.
NVARCHAR prevents data loss in character representation.
What is the storage difference between VARCHAR vs NVARCHAR?
VARCHAR = 1 byte per character; NVARCHAR = 2 bytes per character.
Choose based on character set requirements.
What are VARBINARY/BINARY used for?
Storing files, encrypted data, images, etc.
BINARY types are for binary data storage.