Professional Documents
Culture Documents
Type
int It allows to store whole numbers -2^31 (-2,147,483,648) 2^31-1 (2,147,483,647) 4 byte
between -2,147,483,648 and
2,147,483,647
date It is used to store dates in SQL Server. By default, 0001-01-01 9999-12-31 3 bytes
its format is YYYY-MM-DD, and its value is 1900-
01-01.
datetime It is used to store date and time with fractional 1753-01-01 9999-12-31 8 bytes
seconds. Its default value is 1900-01-01 00:00:00.
Its accuracy is in the increment of .000, .003, or
.007 seconds. It is recommended to avoid this
data type and use datetime2 instead.
datetime2 It specifies date and time with fractional seconds 0001-01-01 9999-12-31 6 to 8
and an accuracy of 100 nanoseconds. It provides 00:00:00 23:59:59.9999999 bytes
precision from 0 to 7 digits. By default, its
precision is 7, and the format is YYYY-MM-DD
hh:mm: ss[.fractional seconds].
datetimeoffset It is the same as datetime2 with the addition of 0001-01-01 9999-12-31 10 bytes
a time zone offset. Its timezone offset value is 00:00:00 23:59:59.9999999
between -14:00 through +14:00.
smalldatetime It specifies a date along with the time of day and 1900-01-01 2079-06-06 4 bytes
an accuracy of 1 minute. Here time is calculated 00:00:00 23:59:59
on a 24-hour clock, with seconds starting at zero
(:00) and no fractional seconds.
binary It is used to store fixed-length binary strings. 0 bytes 8000 bytes n bytes
varbinary It is used to store variable-length binary string. 0 bytes 8000 bytes The actual length
of data entered + 2
bytes
image It is similar to the varbinary data type that can store up 0 bytes 2,147,483,647
to 2 GB. It is recommended to avoid this data type bytes
because it would be deprecated in future releases.
cursor It is an object data type used for variable and stored procedure OUTPUT parameters containing a
reference to a cursor. In addition, it stores temporary table information.. Its output is a column of
sp_cursor_list and sp_describe_cursor that returns the name of the cursor variable.
rowversion It's a data type that returns automatically generated unique binary numbers within a database. It
is commonly used for version-stamping table rows. Its memory storage is 8 bytes. It's an increasing
number that doesn't preserver time and date.
hierarchyid It is a system data type with variable length representing a position in a hierarchy. Its value
represents the position in a tree hierarchy.
uniqueidentifier This data type indicates the 16 byte GUID. It is used to convert a string constant in the form
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. Here, x is a hexadecimal digit (0-9 and a-f).
XML This data type is used to store XML data in a SQL Server table. Its storage limit is 2 GB.
Spatial Geometry It is a spatial planar data type used to represents data in a flat (Euclidean) coordinate system.
Types
Spatial Geography It is a geography spatial data type used for storing ellipsoidal (round-earth) data, such as GPS
Types latitude and longitude coordinates.
sql_variant This data type is used to store values of other SQL Server data types.
table It is a spatial data type used to store the temporary result in a table-valued function. This data is
used for later processing. We can use it by using the syntax as DECLARE @local_variable. It can
also be used in functions, stored procedures, and batches.
Conclusion
This article gives a brief overview of all data types supported in SQL Server. After knowing these data types, we will be aware of using
the appropriate data type for better storage, query processing, and data retrieval.