DEV Community

Kelly Okere
Kelly Okere

Posted on

Understanding SQL Data Types: A Comprehensive Guide with Examples

In the world of relational databases, data types play a crucial role in defining the structure and integrity of data stored in tables. SQL (Structured Query Language) is the standard language for managing and manipulating relational databases, and it provides a wide range of data types to handle different kinds of data. Whether you're working with numbers, text, dates, or other types of data, it's essential to understand the available data types and how to use them effectively. In this article, we'll explore the various SQL data types, their characteristics, and provide examples to help you better understand their usage.

Here is a list of the common data types available in SQL:

  1. Numeric Data Types:

    • INTEGER (or INT)
    • SMALLINT
    • BIGINT
    • DECIMAL (or NUMERIC)
    • REAL
    • DOUBLE PRECISION
    • FLOAT
  2. Character Data Types:

    • CHAR
    • VARCHAR (or VARCHAR2)
    • TEXT (or CLOB - Character Large Object)
  3. Date and Time Data Types:

    • DATE
    • TIME
    • DATETIME (or TIMESTAMP)
  4. Binary Data Types:

    • BINARY
    • VARBINARY (or RAW)
    • BLOB (Binary Large Object)
  5. Boolean Data Type:

    • BOOLEAN (or BOOL)
  6. UUID Data Type:

    • UUID (Universally Unique Identifier)
  7. Spatial Data Types (for storing geometric data):

    • GEOMETRY
    • POINT
    • LINESTRING
    • POLYGON
    • MULTIPOINT
    • MULTILINESTRING
    • MULTIPOLYGON
  8. JSON Data Type (for storing JSON data):

    • JSON
  9. XML Data Type (for storing XML data):

    • XML
  10. User-Defined Data Types:

    • ENUM (for creating a user-defined enumeration)
    • SET (for creating a user-defined set of values)

It is worthy to note that the availability and syntax of specific data types may vary across different database management systems (DBMS) like MySQL, PostgreSQL, Oracle, SQL Server, etc. It's always a good practice to consult the documentation of your DBMS for the exact syntax and usage of data types.

Top comments (0)