SQL

SQL Data Types

SQL Data Types

The concept of data types is very important. Mastering the distinctions and applications of each type offers valuable insight in to SQL.

Similar to other programming languages, SQL supports certain data types.

Each data type has different features, such as:

  • what kind of data can hold
  • what limit can hold
  • what memory is needed

As mentioned previously, different SQL variations differ in some way or another. This holds true for data types as well. Some data types may have different names or features. Or others may not even exists in the particular relational database company.

It all depends on the vendor, and as such, documentation should always be checked. This page covers some of the most popular data types within the SQL Server system.

The following are some of the most commonly used data types.

  • Text: char, varchar, and varchar(max)
  • Numbers: bit, tinyint, smallint, int, bigint, decimal, float, smallmoney, and money
  • Date and time: time, date, and datetime

There are many other data types in SQL. For full documentation, press here.

Text

In SQL, text (also strings or characters) data types deal with text.

This section covers char, varchar, and varchar(max).

  • char stores fixed-size data
  • varchar stores variable-size data
  • varchar(max) stores variable-size data
TypeMinMaxMemory
char(n)18000n bytes
varchar(n)18000n bytes + 2 bytes
varchar(max)12,147,483,647n bytes + 2 bytes

Numbers

In SQL, numbers (also numerics) data types deal with numbers.

There are exact numbers and approximate numbers.

This section covers exact numbers: bit, tinyint, smallint, int, bigint, decimal, smallmoney, and money. It also covers approximate numbers: float.

  • bit stores 0 (FALSE), 1 (TRUE), or NULL data.
  • tinybit stores whole numbers
  • smallint stores whole numbers
  • int stores whole numbers
  • bigint stores whole numbers
  • decimal stores fixed precision and scale numbers
  • float stores approximate floating numbers
  • smallmoney stores monetary or currency numbers
  • money stores monetary or currency numbers
TypeMinMaxMemory
bit011 byte
tinyint02551 byte
smallint-32,76832,7672 byte
int-2,147,483,6482,147,483,6474 bytes
bigint-9,223,372,036,854,775,8089,223,372,036,854,775,8078 bytes
decimal-10^38 +110^38 – 15-17 bytes
float-1.79E+3081.79E+3084 or 8 bytes
smallmoney-214,748.3648214,748.36474 bytes
money-922,337,203,685,477.5808922,337,203,685,477.58078 bytes

Date and time

In SQL, date and time data types deal with dates and times.

This section covers time, date, and datetime.

  • time stores times data
  • date stores dates data
  • datetime stores times and dates data
TypeMinMaxMemory
time00:00:00.000000023:59:59.99999995 bytes
date0001-01-019999-12-313 bytes
datetime0001-01-01 00:00:00.0009999-12-31 23:59:59.9998 bytes

Next: SQL Databases