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.
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. It can use between -2,147,483,648 to 2,147,483,647. |
Smallint | SMALLINT | The smallint data type is used to specify small integer value. It can use between -32,768 to 32,768. |
Numeric | NUMERIC(P,S) | It specifies a numeric value. Here 'p' is precision value and 's' is scale value. It can use between -10^38 +1 to 10^38 -1. |
Real | REAL | The real integer is used to specify a single precision floating point number. It can use between -3.40E + 38 to 3.40E + 38. |
Decimal | DECIMAL(P,S) | It specifies a decimal value. Here 'p' is precision value and 's' is scale value. It can use between -10^38 +1 to 10^38 -1. |
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. It can use between -1.79E + 308 to 1.79E + 308. |
Character | CHAR(X) | Here, 'x' is the character's number to store. Maximum length of 8,000 characters( Fixed length non-Unicode characters). |
Character varying | VARCHAR2(X) | Here, 'x' is the character's number to store. Maximum length of 231characters, Variable-length non-Unicode data (SQL Server 2005 only). |
Bit | BIT(X) | Here, 'x' is the number of bits to store. It can use between 0 to 1. |
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. Stores a date like June 30, 1991. |
Time | TIME | It stores hour, minute and second values. Stores a time of day like 12:30 P.M. |
Timestamp | TIMESTAMP | The timestamp data type is used to store year, month, day, hour, minute and second values. Stores a database-wide unique number that gets updated every time a row gets updated. |
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. |