Skip to main content

What data types exist in SQL?

SQL has several main data types, used to store information in tables. They can be grouped as follows:

1. Numeric types

  • INT / INTEGER, integers, e.g. 10, 200
  • SMALLINT, small integers
  • BIGINT, large integers
  • DECIMAL(p, s) / NUMERIC(p, s), exact fixed-point numbers (p is the total number of digits, s is the number of digits after the decimal point), e.g. 123.45
  • FLOAT / REAL / DOUBLE, floating-point numbers, suited to approximate calculations

2. Character types

  • CHAR(n), a fixed-length string of n characters, e.g. CHAR(10)
  • VARCHAR(n), a variable-length string up to n characters
  • TEXT, large text data

3. Date & Time

  • DATE, a date in YYYY-MM-DD format
  • TIME, a time, e.g. HH:MM:SS
  • DATETIME / TIMESTAMP, a date and time together
  • YEAR, a year

4. The boolean type

  • BOOLEAN, takes the values TRUE / FALSE

5. Other types

  • BLOB, binary data (files, images)
  • JSON, storing data in JSON format (supported by some DBMSs, e.g. MySQL, PostgreSQL)

Put simply, a data type determines which values can be stored in a field, and affects both the memory it uses and the operations that can be performed on that data.

If you'd like, I can put together a table of every data type with examples, to make it easier for a trainee to understand and remember. Should I?

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.