SQL Data Types
SQL Data Types
next → ← prev
Data types are used to represent the nature of the data that can be stored in the database table. For
example, in a particular column of a table, if we want to store a string type of data then we will
have to declare a string data type of this column.
Data types mainly classified into three categories for every database.
CHAR(Size) It is used to specify a fixed length string that can contain numbers,
letters, and special characters. Its size can be 0 to 255 characters.
Default is 1.
VARCHAR(Size) It is used to specify a variable length string that can contain numbers,
letters, and special characters. Its size can be from 0 to 65535
characters.
BINARY(Size) It is equal to CHAR() but stores binary byte strings. Its size parameter
specifies the column length in the bytes. Default is 1.
VARBINARY(Size) It is equal to VARCHAR() but stores binary byte strings. Its size
parameter specifies the maximum column length in bytes.
TEXT(Size) It holds a string that can contain a maximum length of 255 characters.
ENUM(val1, val2, It is used when a string object having only one value, chosen from a
val3,...) list of possible values. It contains 65535 values in an ENUM list. If
you insert a value that is not in the list, a blank value will be inserted.
SET( It is used to specify a string that can have 0 or more values, chosen
val1,val2,val3,....) from a list of possible values. You can list up to 64 values at one time
in a SET list.
BLOB(size) It is used for BLOBs (Binary Large Objects). It can hold up to 65,535
bytes.
BIT(Size) It is used for a bit-value type. The number of bits per value is specified in
size. Its size can be 1 to 64. The default value is 1.
INT(size) It is used for the integer value. Its signed range varies from -2147483648
to 2147483647 and unsigned range varies from 0 to 4294967295. The size
parameter specifies the max display width that is 255.
FLOAT(size, d) It is used to specify a floating point number. Its size parameter specifies
the total number of digits. The number of digits after the decimal point is
specified by d parameter.
DOUBLE(size, It is a normal size floating point number. Its size parameter specifies the
d) total number of digits. The number of digits after the decimal is specified
by d parameter.
DECIMAL(size, It is used to specify a fixed point number. Its size parameter specifies the
d) total number of digits. The number of digits after the decimal parameter is
specified by d parameter. The maximum value for the size is 65, and the
default value is 10. The maximum value for d is 30, and the default value
is 0.
BOOL It is used to specify Boolean values true and false. Zero is considered as
false, and nonzero values are considered as true.
TIMESTAMP(fsp) It is used to specify the timestamp. Its value is stored as the number of
seconds since the Unix epoch('1970-01-01 00:00:00' UTC). Its format is
YYYY-MM-DD hh:mm:ss. Its supported range is from '1970-01-01
00:00:01' UTC to '2038-01-09 03:14:07' UTC.
TIME(fsp) It is used to specify the time format. Its format is hh:mm:ss. Its
supported range is from '-838:59:59' to '838:59:59'
char(n) It is a fixed width character string data type. Its size can be up to 8000
characters.
varchar(n) It is a variable width character string data type. Its size can be up to 8000
characters.
varchar(max) It is a variable width character string data types. Its size can be up to
1,073,741,824 characters.
text It is a variable width character string data type. Its size can be up to 2GB of
text data.
nchar It is a fixed width Unicode string data type. Its size can be up to 4000
characters.
nvarchar It is a variable width Unicode string data type. Its size can be up to 4000
characters.
ntext It is a variable width Unicode string data type. Its size can be up to 2GB of
text data.
binary(n) It is a fixed width Binary string data type. Its size can be up to 8000 bytes.
varbinary It is a variable width Binary string data type. Its size can be up to 8000 bytes.
image It is also a variable width Binary string data type. Its size can be up to 2GB.
float(n) It is used to specify floating precision number data from -1.79E+308 to 1.79E+308.
The n parameter indicates whether the field should hold the 4 or 8 bytes. Default
value of n is 53.
datetime It is used to specify date and time combination. It supports range from January 1,
1753, to December 31, 9999 with an accuracy of 3.33 milliseconds.
datetime2 It is used to specify date and time combination. It supports range from January 1,
0001 to December 31, 9999 with an accuracy of 100 nanoseconds
date It is used to store date only. It supports range from January 1, 0001 to December
31, 9999
timestamp It stores a unique number when a new row gets created or modified. The time
stamp value is based upon an internal clock and does not correspond to real time.
Each table may contain only one-time stamp variable.
Sql_variant It is used for various data types except for text, timestamp, and ntext. It
stores up to 8000 bytes of data.
CHAR(size) It is used to store character data within the predefined length. It can be
stored up to 2000 bytes.
NCHAR(size) It is used to store national character data within the predefined length. It
can be stored up to 2000 bytes.
VARCHAR2(size) It is used to store variable string data within the predefined length. It
can be stored up to 4000 byte.
NVARCHAR2(size) It is used to store Unicode string data within the predefined length. We
have to must specify the size of NVARCHAR2 data type. It can be
stored up to 4000 bytes.
NUMBER(p, s) It contains precision p and scale s. The precision p can range from 1 to
38, and the scale s can range from -84 to 127.
FLOAT(p) It is a subtype of the NUMBER data type. The precision p can range
from 1 to 126.
DATE It is used to store a valid date-time format with a fixed length. Its range varies
from January 1, 4712 BC to December 31, 9999 AD.
TIMESTAMP It is used to store the valid date in YYYY-MM-DD with time hh:mm:ss
format.
BFILE It is used to store binary data in an external file. Its range goes up to 232-1 bytes
or 4 GB.
CLOB It is used for single-byte character data. Its range goes up to 232-1 bytes or 4
GB.
NCLOB It is used to specify single byte or fixed length multibyte national character set
(NCHAR) data. Its range is up to 232-1 bytes or 4 GB.
RAW(size) It is used to specify variable length raw binary data. Its range is up to 2000 bytes
per row. Its maximum size must be specified.
LONG It is used to specify variable length raw binary data. Its range up to 231-1 bytes
RAW or 2 GB, per row.
Next TopicSQL Operators
← prev next →