Common column data types and table constraints including check, unique, and foreign key, each explained with a short example.
36 cards · basic cards · AI-written, checked twice. Edit anything.
- What is the CHAR data type used for?
- Fixed-length string storage. Always allocates the specified number of bytes regardless of actual string length.
- What is the VARCHAR data type used for?
- Variable-length string storage. Only allocates space for the actual string content, up to a maximum length.
- When should you use CHAR instead of VARCHAR?
- When you have fixed-length values, like postal codes (5 digits), state abbreviations (2 letters), or gender codes.
- What is the INT data type used for?
- Storing whole numbers. Typically ranges from about -2 billion to +2 billion.
- What is the BIGINT data type used for?
- Storing very large whole numbers, ranging from about -9 quintillion to +9 quintillion.
- What is the SMALLINT data type used for?
- Storing smaller whole numbers, ranging from about -32,000 to +32,000. Uses less storage than INT.
- What is the DECIMAL data type used for?
- Storing exact decimal numbers. Defined with precision (total digits) and scale (digits after decimal point), like DECIMAL(10,2).
- What is the FLOAT data type used for?
- Storing approximate decimal numbers using floating-point representation. Takes less storage than DECIMAL but may lose precision.
- When should you use DECIMAL instead of FLOAT?
- For financial calculations and any scenario where exact precision is critical. DECIMAL stores values exactly, FLOAT is approximate.
- What is the DATE data type used for?
- Storing dates without time information. Format is typically YYYY-MM-DD.
- What is the TIME data type used for?
- Storing time without date information. Format is typically HH:MM:SS.
- What is the DATETIME data type used for?
- Storing both date and time together. Format is typically YYYY-MM-DD HH:MM:SS.
- What is the BOOLEAN data type used for?
- Storing true or false values. Some databases represent this as 1 for true and 0 for false.
- What is the TEXT data type used for?
- Storing large amounts of text data. More flexible than VARCHAR and suitable for long documents or descriptions.
- What is the BLOB data type used for?
- Storing binary large objects like images, audio, or video files as raw binary data.