Krivalar Tutorials 
Krivalar Tutorials



SQL Data Types

<< Previous - SQL Syntax

Next SQL Create Database>>






Data type is used to represent the kind of data that database of tables can hold.

SQL data types

  • Exact Numeric data type
  • Approximate Numeric data type
  • Character String data type
  • Date and Time data type
  • Binary data type
  • Other data type

SQL - Exact Numeric Data Type - INTEGER

KeywordRangeStorage size
bit(size)0,1 or NULL1 bit
tinyint 0 to 2551 bytes
smallint-32,768 to 32,7672 bytes
int(size)-2,147,483,648 to 2,147,483,6474 bytes
bigint-2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807)8 bytes
decimal(p,[s]) -10^38+1 to +10^38-1 5-17 bytes
numeric(p,[s]) -10^38+1 to +10^38-15-17 bytes
Smallmoney -214,748.3648 to +214,748.36474 bytes
Money-922,337,203,685,477.5808 to +922,337,203,685,477.5807 8 bytes



SQL - Approximate Numeric Data Types - float and real

KeywordRangeStorage size
float-1.79E+308 to 1.79E+3084-8 bytes
real-3.40E+38 to 3.40E+384 bytes

SQL Data Type - Character

DatatypeDescription
char(n)n=1 to 8000 fixed length non- unicode character.
varchar(n/max) n= 1 to 8000 variable length non unicod characters. max= 2E+31 variable length nonunicode characters.
text(n)n=1 to 2,147,483,647 (2GB) variable length unicode characters.

Unicode Character String Data Types

DatatypeDescription
nchar(n) n=1 to 4000 fixed length unicode characters string.
nvarchar(n/max) n= 1 to 4000 variable length unicod characters string. max= 2E+31 variable length unicode charaters string.
ntext Variable length unicode characters string with maximum length of 1,073,741,823 characters.

SQL Binary Data Types

DatatypeDescription
binary Fixed length binary data with maximum length of 8000 bytes
varbinary Variable length binary data with maximum length of 8000 bytes
varbinary(max) Variable length binary data with maximum length of 2E+31 bytes(SQL server 2005 only)
image Variable length binary data with maximum length of 2,147,483,64bytes

SQL Date and Time Data Types

DatatypeDescriptionSize
datetimeDatetime used to store both date and time with accuracy of 3.33 milliseconds. Format: YYYY-MM-DD hh:mm:ss. Date range from Jan 1, 1753 to Dec 31,9999 and time range from 00:00:00 to 23:59:59.9978 bytes
smalldatetimeDate range from Jan 1, 1900 to Jun 30 ,2079 and time range from 00:00:00 to 23:59:594 bytes
dateDate in SQL stores only date and its range from Jan 1, 001 to Dec 31, 9999 Format:YYYY-MM-DD3 bytes
timeTime in SQL Stores only time with accuracy of 100 nanoseconds. Its range from 00:00:0000000 to 23:59:59.9999999 Format:hh:mm:ss3 to 5
timestamptimestamp specifies the date, time and timezone information

<< Previous - SQL Syntax

Next SQL Create Database >>









Searching using Binary Search Tree