Below is a SQL data types cheat sheet covering common data types used in relational database management systems (RDBMS). Note that specific databases may have variations or additional types.
Numeric Data Types
- INTEGER/INT:
- Whole numbers, e.g., 1, -5, 100.
- SMALLINT:
- Small range integers.
- BIGINT:
- Large range integers.
- DECIMAL/NUMERIC:
- Fixed-point numbers, e.g., 10.45.
- FLOAT:
- Floating-point numbers.
- REAL:
- Single-precision floating-point numbers.
- DOUBLE PRECISION:
- Double-precision floating-point numbers.
Character String Data Types
- CHAR(n):
- Fixed-length character string, e.g., CHAR(10).
- VARCHAR(n):
- Variable-length character string, e.g., VARCHAR(255).
- TEXT:
- Variable-length character string with larger capacity.
Date and Time Data Types
- DATE:
- Date, e.g., ‘2022-01-01’.
- TIME:
- Time of day, e.g., ’12:30:00′.
- DATETIME:
- Date and time, e.g., ‘2022-01-01 12:30:00’.
- TIMESTAMP:
- Date and time with timezone information.
Boolean Data Type
- BOOLEAN/BOOL:
- Represents true or false values.
Binary Data Types
- BINARY(n):
- Fixed-length binary data.
- VARBINARY(n):
- Variable-length binary data.
- BLOB:
- Binary Large Object for larger binary data.
Miscellaneous Data Types
- ENUM:
- Enumeration, a list of predefined values.
- SET:
- A set of values chosen from a predefined list.
- JSON:
- Stores JSON data.
Spatial Data Types
- GEOMETRY:
- Represents geometric shapes in 2D space.
- GEOGRAPHY:
- Represents locations on Earth’s surface.
Special Data Types
- NULL:
- Represents a missing or unknown value.
User-Defined Data Types
- USER-DEFINED:
- Custom data types defined by the user.
Note:
- Data types may have variations in different database systems (e.g., MySQL, PostgreSQL, SQL Server).
- Always refer to the documentation of the specific database you are using for the most accurate and detailed information.
- Some databases may offer additional or database-specific data types.
This cheat sheet provides a general overview of common SQL data types. Specific implementations and usage may vary, so it’s essential to consult the documentation of the specific database you are working with for precise information.