SQL Server - DATA TYPES



SQL Server - DATA TYPES


A data type is an attribute that specifies the type of data that the object can hold: integer data, character data, monetary data, date and time data, binary strings, and so on. SQL Server supplies a set of system data types that define all the types of data that can be used with SQL Server.


Below are the Data Type categories in SQL Server

Categories
Exact numerics
Approximate numerics
Date and time
Character strings
Unicode character strings
Binary strings
Other data types

Exact numerics

DatatypeRangeStorage
bigint-2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807)8 bytes
int-2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647)4 bytes
smallint-2^15 (-32,768) to 2^15-1 (32,767)2 bytes
tinyint0 to 2551 byte
bit0-1-
decimal-10^38 +1 to 10^38 -15-17 bytes
numeric-10^38 +1 to 10^38 -15-17 bytes
money-922,337,203,685,477.5808 to 922,337,203,685,477.5807 (-922,337,203,685,477.58 to 922,337,203,685,477.58 for Informatica. Informatica only supports two decimals, not four.)8 bytes
smallmoney- 214,748.3648 to 214,748.36474 bytes

Approximate numerics

DatatypeDescriptionRange
floatFloating point Numeric data.n is the number of bits that are used to store the mantissa of the float number in scientific notation and, therefore, dictates the precision and storage size. If nis specified, it must be a value between 1 and 53. The default value of n is 53. If n valueIf 1<=n<=24, n is treated as 24, precision will be 7 digits and storage size will be 4 bytes.If 25<=n<=53, n is treated as 53, precision will be 15 digits and storage size will be 8 bytes-1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308
realREAL is FLOAT(24)4 Bytes-3.40E + 38 to -1.18E -38, 0 and 1.18E -38 to 3.40E +38

Date and Time

DatatypeDescriptionStorage sizeAccuracyLower rangeUpper range
dateTimeUsed for specifying a date and time from January 1, 1753 to December 31, 9999.It has an accuracy of 3.33 milliseconds8 bytesRounded to increments of .000, .003, .0071753-01-019999-12-31
smalldatetimeUsed for specifying a date and time from January 1, 0001 to December 31, 9999. It has an accuracy of 100 nanoseconds4 bytes, fixed1 minute1900-01-012079-06-06
dateUsed to store only date from January 1, 0001 to December 31, 99993 bytes, fixed1day0001-01-019999-12-31
timeUsed for storing only time only values with an accuracy of 1005 bytes100 nanoseconds00:00:00.000000023:59:59.9999999
datetime2Used for specifying a date and time from January 1, 0001 to December 31, 99996 bytes100 nanoseconds0001-01-019999-12-31
datatimeoffsetSimilar to datatime but has a time zone offset10 bytes100 nanoseconds0001-01-019999-12-31

Character strings

Character string allows the user to define the data type of character which can be of fixed and variable length.

DatatypeDescriptionLower limitUpper limitMemory
charIt is a character string with a fixed width. It stores a maximum of 8,000 characters0 chars8000 charsn bytes
varcharThis is a character string with variable width0 chars8000 charsn bytes + 2 bytes
varchar(max)This is a character string with a variable width. It stores a maximum of 1,073,741,824 characters0 chars1,073,741,824 charactersn bytes + 2 bytes
textThis is a character string with a variable width. It stores a maximum 2GB of text data0 chars2,147,483,647 charsn bytes + 4 bytes

Unicode characters

DatatypeDescriptionLower limitUpper limitMemory
ncharIt is a Unicode string of fixed width0 chars4000 chars2 times n bytes
nvarcharIt is a unicode string of variable width0 chars4000 chars2 times n bytes + 2 bytes
ntextIt is a unicode string of variable width0 chars1,073,741,823 char2 times the string length

Binary string

Binary string contains a binary string of fixed and variable length.


DatatypeDescriptionLower limitUpper limitMemory
binaryIt is a fixed width binary string. It stores a maximum of 8,000 bytes0 bytes8000 bytesN bytes
varbinaryThis is a binary string of variable width. It stores a maximum of 8,000 bytes0 bytes8000 bytesThe actual length of data entered + 2 bytes
imageThis is a binary string of variable width. It stores a maximum of 2GB0 bytes2,147,483,647 bytes-

Other Datatypes

DatatypeDescription
CursorIts output is a column of sp_cursor_list and sp_describe_cursor. It returns the name of the cursor variable
Row versionIt version stamps table rows
HierarchyidThis datatype represents a position in the hierarchy
UniqueidentifierConversion from a character expression
Sql_variantIt stores values of SQL server supported Datatypes
XMLIt stores XML data in a column
Spatial Geometry typeIt represents data in a flat coordinate system
Spatial Geography typeIt represents data in the round-earth coordinate system
tableIt stores a result set for later processing


Connection String

SQL Server Connection String Formats

posted on 2019-08-27 05:53:53 - SQL Server Tutorials


UNION

union in SQL server

posted on 2019-08-09 23:05:33 - SQL Server Tutorials


System Functions

System Functions in SQL Server

posted on 2019-08-09 06:14:33 - SQL Server Tutorials


Prompt Examples

ChatGPT Prompt Examples

posted on 2023-06-21 22:37:19 - ChatGPT Tutorials


Use Cases

Chat GPT Key Use Cases

posted on 2023-06-21 21:03:17 - ChatGPT Tutorials


Prompt Frameworks

Prompt Frameworks

posted on 2023-06-21 19:33:06 - ChatGPT Tutorials