SQL Data Types
The SQL data
type defines a kind of value that a column can contain.
In a database
table, every column is required to have a name and a data type.
Data Type varies from database
to database. For example, MySQL supports INT but Oracle supports NUMBER for
integer values.
These are the
general data types in SQL.
Data-type
|
Syntax
|
Explanation
|
Integer
|
INTEGER
|
The integer data type is used to specify an integer value.
|
Smallint
|
SMALLINT
|
The smallint data type is used to specify small integer value.
|
Numeric
|
NUMERIC(P,S)
|
It specifies a numeric value. Here 'p' is precision value and
's' is scale value.
|
Real
|
REAL
|
The real integer is used to specify a single precision floating
point number.
|
Decimal
|
DECIMAL(P,S)
|
It specifies a decimal value. Here 'p' is precision value and
's' is scale value.
|
Double precision
|
DOUBLE PRECISION
|
It specifies double precision floating point number.
|
Float
|
FLOAT(P)
|
It specifies floating-point value e.g. 12.3, 4.5 etc. Here, 'p'
is precision value.
|
Character
|
CHAR(X)
|
Here, 'x' is the character's number to store.
|
Character varying
|
VARCHAR2(X)
|
Here, 'x' is the character's number to store
|
Bit
|
BIT(X)
|
Here, 'x' is the number of bits to store
|
Bit varying
|
BIT VARYING(X)
|
Here, 'x' is the number of bits to store (length can vary up to
x).
|
Date
|
DATE
|
It stores year, month and days values.
|
Time
|
TIME
|
It stores hour, minute and second values
|
Timestamp
|
TIMESTAMP
|
The timestamp data type is used to store year, month, day, hour,
minute and second values.
|
Time with time zone
|
TIME WITH TIME ZONE
|
It is exactly same as time but also store an offset from UTC of
the time specified.
|
Timestamp with time zone
|
TIMESTAMP with TIME ZONE
|
It is same as timestamp but also stores an offset from UTC of
the time specified.
|
Comments
Post a Comment