Skip to main content

SQL, data types

In SQL, data types define the type of data that can be stored in a column. Here are some common SQL data types:

img

Numeric Data Types

  1. INT: Integer values.

    • Example: INT, INTEGER
  2. FLOAT: Floating-point numbers.

    • Example: FLOAT, DOUBLE
  3. DECIMAL: Fixed-point numbers, useful for storing exact numeric values.

    • Example: DECIMAL(10, 2) (10 digits in total, 2 after the decimal point)
  4. SMALLINT: Smaller integer values.

    • Example: SMALLINT
  5. BIGINT: Larger integer values.

    • Example: BIGINT

Character String Data Types

  1. CHAR: Fixed-length character strings.

    • Example: CHAR(10) (10 characters)
  2. VARCHAR: Variable-length character strings.

    • Example: VARCHAR(255)
  3. TEXT: Large variable-length character strings.

    • Example: TEXT

Date and Time Data Types

  1. DATE: Date values.

    • Example: DATE (format: YYYY-MM-DD)
  2. TIME: Time values.

    • Example: TIME (format: HH:MM:SS)
  3. DATETIME: Date and time values.

    • Example: DATETIME (format: YYYY-MM-DD HH:MM:SS)
  4. TIMESTAMP: Date and time values, typically used for tracking changes in records.

    • Example: TIMESTAMP (format: YYYY-MM-DD HH:MM:SS)

Boolean Data Type

  1. BOOLEAN: Stores TRUE or FALSE.
    • Example: BOOLEAN

Binary Data Types

  1. BINARY: Fixed-length binary data.

    • Example: BINARY(10)
  2. VARBINARY: Variable-length binary data.

    • Example: VARBINARY(255)
  3. BLOB: Large binary objects.

    • Example: BLOB

Other Data Types

  1. ENUM: Enumeration, a string object that can have one value chosen from a list of permitted values.

    • Example: ENUM('small', 'medium', 'large')
  2. SET: A string object that can have zero or more values, each chosen from a list of permitted values.

    • Example: SET('a', 'b', 'c')

These are some of the most commonly used data types in SQL. Different SQL database systems may have additional data types or slight variations in the names and specifications of these data types.