SQL Data Types and Dialects

What are the four types of data types?

Many SQL guides group data types into four families: numeric, character, date and time, and a fourth that varies. Here is what each family holds.

On this page
  1. No single list of four
  2. Numeric types
  3. Character (string) types
  4. Date and time types
  5. The fourth family
  6. Practical points

No single list of four

The SQL standard doesn’t define a list of four data types. It distinguishes predefined, constructed and user-defined types, and most learner guides use a more practical grouping. Many guides split the common SQL data types into four families: numeric, character (string), date and time, and a fourth family that varies by guide. Others use three, five or six groups. The names below are common across products, but the exact syntax and limits depend on the database.

Numeric types

Numeric types hold numbers. Whole numbers use INTEGER (often written INT), SMALLINT or BIGINT. Exact decimals use DECIMAL or NUMERIC, which suit money. Approximate numbers use FLOAT, REAL or DOUBLE PRECISION, which suit measurements but can’t store every decimal exactly. A value such as 0.1 is one example.

Character (string) types

Character types hold text. CHAR(n) is fixed-length, VARCHAR(n) is variable-length up to n characters, and TEXT holds long strings. In standard SQL, the term “character string” covers CHAR, VARCHAR and CLOB. SQL Server adds NCHAR and NVARCHAR for Unicode text.

Function names for text length also differ. SQL Server uses LEN, and MySQL’s LENGTH() counts bytes rather than characters. For the details, see “What is length() in SQL?”

Date and time types

Date and time types hold calendar dates and times of day. The standard names are DATE, TIME and TIMESTAMP, and it also defines INTERVAL for durations. MySQL and SQL Server add DATETIME. Time zone handling differs between products, so check the manual before storing times across regions. SQLite has no date type and stores dates as text, numbers or integers. Keep dates in a real date type rather than text, so sorting and date arithmetic work correctly.

The fourth family

Depending on the guide, the fourth family is one of these:

  • Boolean, for TRUE or FALSE values. PostgreSQL has a native boolean type, SQL Server uses BIT, and MySQL’s BOOLEAN is a synonym for TINYINT(1).
  • Binary, for raw bytes such as files and images. Examples are BLOB, BYTEA in PostgreSQL and VARBINARY in SQL Server.
  • Specialized, such as JSON and XML for structured or semi-structured data.

Which family you call the fourth matters less than knowing what each type holds and where your database differs.

Practical points

  • Most columns accept NULL unless they are declared NOT NULL. NULL isn’t zero or an empty string. For replacing missing values, see “How to get 0 instead of NULL in SQL?” and “What is coalesce() in SQL?”
  • Pick the narrowest type that fits your data, and use DECIMAL for money.
  • Learn the types early. Type mismatches are a common source of errors, so knowing what each family holds helps when a query fails.

The complete guide to sql data types and dialects

The Different Data Types of SQL and When to Use Each
Read the guide

Keep exploring

Guides from other topics

All topics →