TipsMake

Data types in SQL Server

Below are the data types (data types) in SQL Server, including character strings, numbers and times / dates.

Below are the data types (data types) in SQL Server, including character strings, numbers and times / dates.

Character string data type in SQL Server

Below are the types of character string data in SQL Server (Transact-SQL).

Data type syntax Maximum size Explanation CHAR (kich_thuoc) Maximum of 8000 characters.
  • kich_thuoc is the number of characters stored.
  • Fixed length.
  • Add a space to the right to offset the space for enough characters.
  • Does not contain Unicode characters.
VARCHAR (kich_thuoc) or VARCHAR (toi_da) Maximum of 8000 characters or maximum number.
  • kich_thuoc is the number of characters stored.
  • Custom length.
  • If specified as toi_da, the maximum is 2GB.
  • Does not contain Unicode characters.
TEXT Max 2GB.
  • Custom length.
  • Does not contain Unicode characters.
NCHAR (kich_thuoc) Maximum of 4000 characters.
  • Fixed length.
  • Unicode character.
NVARCHAR (kich_thuoc) or NVARCHAR (toi_da) Maximum of 4000 characters or maximum number.
  • kich_thuoc is the number of characters stored.
  • Custom length.
  • If the number toi_da is specified, the maximum number of characters is 2GB.
  • Unicode character.
NTEXT Maximum 1,073,741,823 bytes.
  • Custom length.
  • Unicode character.
BINARY (kich_thuoc) Maximum of 8000 characters.
  • kich_thuoc is the number of characters stored.
  • Fixed length.
  • Add a space to compensate the space for enough characters.
  • Binary data.
VARBINARY (kich_thuoc) or VARBINARY (toi_da) Maximum of 8000 characters or maximum number.
  • kich_thuoc is the number of characters stored.
  • Custom length.
  • If specified as toi_da, the maximum is 2GB.
  • Binary data.
IMAGE maximum size is 2GB.
  • Custom length.
  • Binary data.

Data type in SQL

Digital data type in SQL Server

Below is a list of numeric data types in SQL Server (Transact-SQL).

Syntax of data type Maximum size Explain BIT integers 0, 1 or NULL TINYINT from 0 to 255 SMALLINT from -32768 to 32767 INT -2,147,483,648 to 2,147,483,647 BIGINT from -9,223,372,036,854,775,808 to 9,223,372,036,808,80,807 DECIMAL (m, d)
  • The default m is 18 if not specified.
  • d default is 0 if not specified.
m is the total number of numbers and d is the number of numbers after the comma. DEC (m, d)
  • The default m is 18 if not specified.
  • d default is 0 if not specified.

m is the total number of numbers and d is the number of numbers after the comma.

Synonym with DECIMAL data type.

NUMERIC (m, d)
  • The default m is 18 if not specified.
  • d default is 0 if not specified.

m is the total number of numbers and d is the number of numbers after the comma.

Synonym with DECIMAL data type.

FLOAT (n) number of commas n is defaulted to 53 if not specified. n is the number of bits stored in a chemical symbol. REAL is equivalent to FLOAT (24) SMALLMONEY from - 214,748.3648 to 214,748.3647 MONEY from -922,337,203,685,477,5808 to 922,337,203,685,477,5807

Date / time data type in SQL Server

Below is a list of date / time data types in SQL Server (Transact-SQL).

Syntax of data type Maximum size Explain DATE value from '0001-01-01' to '9999-12-31. displayed as 'YYYY-MM-DD' DATETIME
  • Date taken from '1753-01-01 00:00:00' to '9999-12-31 23:59:59'.
  • Hours are taken from '00: 00: 00' to '23: 59: 59: 997'
displayed as' YYYY-MM-DD hh: mm: ss [.mmm] DATETIME2 (accurate to the decimal number of seconds)
  • value taken from '0001-01-01' to '9999-12-31'.
  • Time taken from '00: 00: 00 'to' 23: 59: 59: 9999999 '.
displayed as 'YYYY-MM-DD hh: mm: ss [. decimal seconds]' SMALLDATETIME
  • The value is from '1900-01-01' to '2079-06-06'.
  • Time taken from '00: 00: 00 'to' 23: 59: 59 '.
displayed as' YYYY-MM-DD hh: mm: ss TIME
  • The value is from '00: 00: 00.0000000 'to' 23: 59: 59.9999999 '.
  • Date taken from '0001-01-01' to '9999-12-31'.
displayed as 'YYYY-MM-DD hh: mm: ss [.nnnnnnn]' DATETIMEOFFSET (accurate to decimal number of seconds)
  • time value taken from '00: 00: 00 'to' 23: 59: 59: 9999999 '.
  • Time zone taken from -14: 00 to +14: 00.
displayed as YYYY-MM-DD hh: mm: ss [.nnnnnnn] '[{+ | -} hh: mm]

Previous article: PIVOT clause in SQL Server

The following article: CREATE TABLE command in SQL Server

Discover more

MS SQL Server SQL Server data type data types in SQL Server mssql
Isabella Humphrey

Share by

Isabella Humphrey
Update 25 May 2019