Understanding SQL data types is fundamental for designing efficient and reliable databases. They define the kind of data that can be stored in a column, influencing storage, operations, and data integrity.
Used for storing numerical values. Precision and range vary between types.
INT or INTEGER: Whole numbers.DECIMAL(p, s) or NUMERIC(p, s): Exact fixed-point numbers with precision 'p' and scale 's'.FLOAT or REAL: Approximate floating-point numbers.DOUBLE PRECISION: Approximate floating-point numbers with higher precision.BIGINT: Larger whole numbers.SMALLINT: Smaller whole numbers.TINYINT: Very small whole numbers.Used for storing temporal information.
DATE: Stores year, month, and day.TIME: Stores hour, minute, and second.DATETIME or TIMESTAMP: Stores date and time combination.YEAR: Stores the year.INTERVAL: Represents a duration.Used for storing character data.
VARCHAR(n): Variable-length string with a maximum length 'n'.CHAR(n): Fixed-length string, padded with spaces if necessary.TEXT: For longer text strings without a fixed limit (though databases often impose internal limits).BLOB: Binary Large Object, for storing binary data like images or files.ENUM: A string object whose value must be from a list of allowed values.Includes logical values and other specialized types.
BOOLEAN or BOOL: Stores TRUE or FALSE values.JSON: Stores JSON documents.UUID: Universally Unique Identifier.XML: Stores XML data.Consider the following when selecting a data type: