Database data types are classifications of the types of data that can be stored in a database. Understanding the available data types is crucial for structuring data properly, optimizing performance, and ensuring data integrity. While the exact set of data types can vary slightly depending on the database system (like MySQL, PostgreSQL, Oracle, etc.), here are 100 common database data types, organized into different categories:
Numeric Data Types
- INT (or INTEGER) โ Integer values without decimals.
- SMALLINT โ Small integer values.
- BIGINT โ Large integer values.
- TINYINT โ Very small integer values.
- DECIMAL โ Fixed-point numbers with a defined scale and precision.
- NUMERIC โ Similar to DECIMAL, stores exact numeric data.
- FLOAT โ Floating-point numbers (approximate).
- REAL โ A smaller floating-point number.
- DOUBLE โ Double-precision floating-point numbers.
- MONEY โ Monetary values, often formatted for financial data.
- SERIAL โ Auto-incrementing integer values, often used for primary keys (PostgreSQL).
- BIGSERIAL โ Similar to SERIAL but with a larger range (PostgreSQL).
- BIT โ Stores binary data, typically 1 or 0.
Character and String Data Types
- CHAR โ Fixed-length character string.
- VARCHAR โ Variable-length character string.
- TEXT โ Large text data.
- CHARACTER โ Equivalent to CHAR.
- VARCHAR2 โ Variable-length character string (Oracle-specific).
- CLOB โ Character large object, stores large amounts of text data.
- BLOB โ Binary large object, stores large binary data.
- ENUM โ A predefined set of string values.
- SET โ A set of values (usually for flags or choices).
- NCHAR โ Fixed-length string for Unicode characters.
- NVARCHAR โ Variable-length string for Unicode characters.
- NTEXT โ Unicode text data.
Date and Time Data Types
- DATE โ Stores date (year, month, day).
- TIME โ Stores time (hours, minutes, seconds).
- DATETIME โ Stores date and time.
- TIMESTAMP โ Similar to DATETIME, often includes fractional seconds.
- YEAR โ Stores year data (e.g., 2025).
- SMALLDATETIME โ A smaller range of DATETIME.
- TIME WITH TIME ZONE โ Time with time zone information.
- TIMESTAMP WITH TIME ZONE โ Timestamp with time zone information.
- DATE/TIME WITHOUT TIME ZONE โ Only date or time without time zone info.
- INTERVAL โ Represents a duration of time (can store differences between two dates).
Binary Data Types
- BINARY โ Fixed-length binary data.
- VARBINARY โ Variable-length binary data.
- IMAGE โ Stores binary data, usually images or media files.
- BYTEA โ Stores binary data (PostgreSQL).
- UUID โ Universally Unique Identifier, often used for global unique keys.
Boolean Data Type
- BOOLEAN โ Stores Boolean values (TRUE, FALSE, or NULL).
Geospatial Data Types
- POINT โ Stores a point in 2D space.
- LINESTRING โ Stores a series of points, forming a line.
- POLYGON โ Stores a polygon shape.
- MULTIPOINT โ Stores multiple points.
- MULTILINESTRING โ Stores multiple lines.
- MULTIPOLYGON โ Stores multiple polygons.
- GEOMETRY โ Generic spatial data type (can store any spatial data).
- GEOGRAPHY โ Similar to GEOMETRY, but with more advanced features for handling geographic data.
- GEOMETRYCOLLECTION โ A collection of geometric objects.
JSON and XML Data Types
- JSON โ Stores JSON (JavaScript Object Notation) formatted data.
- JSONB โ Stores JSON data in a binary format (PostgreSQL).
- XML โ Stores XML (eXtensible Markup Language) data.
- JSONPATH โ Stores a reference to a particular path within JSON data.
Array Data Types
- ARRAY โ Stores a collection of values (e.g., an array of integers).
- HSTORE โ Stores key-value pairs (PostgreSQL).
Network and IP Data Types
- INET โ Stores IP addresses (IPv4 or IPv6).
- CIDR โ Stores an IP network range.
- MACADDR โ Stores MAC addresses.
Interval and Duration Data Types
- INTERVAL โ Represents the difference between two dates or times (e.g., 10 days, 5 hours).
- TIMESTAMP WITH INTERVAL โ Timestamp including an interval.
Monetary Data Types
- MONEY โ A currency value (often with 2 decimal places).
- DECIMAL (also used for currency) โ Numeric data type with fixed precision.
- CURRENCY โ A representation of currency values (varies by DBMS).
Specialized Numeric Types
- NUMBER โ Numeric type, specific to Oracle databases.
- FLOAT8 โ 8-byte floating-point value (PostgreSQL).
- NUMERIC โ Fixed-precision numeric value.
Hash and Checksum Data Types
- HASH โ Stores hash values generated from a string.
- CHECKSUM โ Stores a checksum value to ensure data integrity.
Composite and User-defined Data Types
- ROW โ A composite data type that stores a record.
- RECORD โ A composite data type used in PostgreSQL.
- USER-DEFINED TYPES (UDT) โ Custom data types defined by the user (can represent complex structures).
- ARRAY of USER-DEFINED TYPES โ Arrays of complex user-defined data types.
- UUIDARRAY โ Array of UUID values.
Timezone and Offset Data Types
- TIMEZONE โ A time data type that includes a timezone.
- TIMESTAMP WITH TIMEZONE OFFSET โ Stores timestamp with a timezone offset.
- DATETIME WITH OFFSET โ Stores date and time with timezone offset.
File and Large Object Data Types
- FILE โ Stores file data (e.g., file paths).
- BLOB (Binary Large Object) โ Stores large binary data like images, video, and files.
- CLOB (Character Large Object) โ Stores large text data.
- TEXT โ Stores large text or unstructured data.
- VARBINARY โ Variable-length binary data used to store files.
Date and Time Precision Types
- DATE WITH PRECISION โ Date data type that includes time precision (milliseconds, microseconds, etc.).
- DATETIME(6) โ DATETIME type with microsecond precision.
- TIME(3) โ TIME type with millisecond precision.
Multi-dimensional Data Types
- MATRIX โ Stores a matrix (multidimensional array) of values.
- VECTOR โ Stores a vector (one-dimensional array) of numeric values.
Enumeration and Set Data Types
- ENUM โ A set of predefined values (useful for categorical data).
- SET โ Similar to ENUM, but stores multiple values (e.g., flags).
Full-Text and Document Data Types
- TEXTSEARCH โ Stores text data designed for full-text search operations.
- DOCUMENT โ A data type designed for document storage and retrieval (commonly used with document databases).
- FULLTEXT โ Stores indexed text for fast full-text search.
- XMLDOCUMENT โ Stores XML documents for structured data.
Large Integer Data Types
- BIGSERIAL โ Large auto-incrementing integer values (PostgreSQL).
- BIGINT โ Integer with a larger range.
- LONG โ A very large number (used in some databases like Oracle).
Geospatial Indexing Types
- GEOMETRY INDEX โ An index for spatial (geometry) data types.
- R-Tree โ An index used for spatial queries (like polygons).
- GiST โ Generalized Search Tree index for various complex data types.
Specialized Boolean Data Types
- BOOLEAN ARRAY โ Array of Boolean values (TRUE/FALSE).
Conclusion
These are just some of the database data types available in popular database management systems like MySQL, PostgreSQL, Oracle, and SQL Server. Different databases have different data type implementations and capabilities, but this list should give you a good understanding of the variety of types that can be used for managing and optimizing data. Properly selecting the right data type for each piece of data is crucial for performance, storage efficiency, and ensuring the integrity of your database.