SQL Getting Sta...login
SQL Getting Started Tutorial Manual
author:php.cn  update time:2022-04-12 14:15:40

SQL common data types



Data type defines the type of value stored in the column.


SQL common data types

Each column in a database table requires a name and data type. Each column in a database table is required to have a name and a data type.

SQL developers must decide when creating a SQL table the type of data that each column in the table will store. A data type is a label that is a guide for SQL to understand what type of data each column is expected to store. It also identifies how SQL interacts with the stored data.

The following table lists the common data types in SQL:

Data typeDescription
CHARACTER(n)Character/String. Fixed length n.
VARCHAR(n) or
CHARACTER VARYING(n)
character/string. Variable length. Maximum length n.
BINARY(n)Binary string. Fixed length n.
BOOLEANStoring TRUE or FALSE value
VARBINARY(n) or
BINARY VARYING(n)
Binary string. Variable length. Maximum length n.
INTEGER(p)Integer value (no decimal point). Precision p.
SMALLINTInteger value (no decimal point). Accuracy 5.
INTEGERInteger value (no decimal point). Accuracy 10.
BIGINTInteger value (no decimal point). Accuracy 19.
DECIMAL(p,s)Exact value, precision p, number of decimal places s. For example: decimal(5,2) is a number with 3 digits before the decimal point and 2 digits after the decimal point.
NUMERIC(p,s)Exact numerical value, precision p, number of decimal places s. (Same as DECIMAL)
FLOAT(p)Approximate numerical value, mantissa precision p. A floating-point number in base 10 exponential notation. The size parameter of this type consists of a single number that specifies the minimum precision.
REALApproximate numerical value, mantissa precision 7.
FLOAT Approximate numerical value, mantissa precision 16.
DOUBLE PRECISIONApproximate numerical value, mantissa precision 16.
DATE Stores the value of year, month and day.
TIME Stores the values ​​of hours, minutes, and seconds.
TIMESTAMP Stores the value of year, month, day, hour, minute and second.
INTERVAL consists of some integer fields, representing a period of time, depending on the type of interval.
ARRAYA fixed-length ordered set of elements
MULTISETA variable set of elements Unordered collection of length
XMLStoring XML data


SQL Data Type Quick Reference Manual

However, different databases provide different options for data type definition.

The following table shows the common names of some data types on various database platforms:

Yes/NoBitByteN/ABooleanNumber (integer)IntNumberIntIntNumber (single)FloatNumberFloatNumericCurrencyMoneyN /AN/AMoneyN/ACharCharCharChar##string (variable)Memo (65k+)Varchar2binary objectVarbinary (<8K)RawTextVarbinary
Data TypesAccessSQLServerOracleMySQLPostgreSQL
##boolean
integer Integer
Integer
floatReal
currency
string (fixed)
Text (<256)
Varchar
Varchar
Varchar
Varchar
OLE Object MemoBinary (fixed up to 8K)Image (<2GB)

Long

Blob

Binary


lampNote:

In different databases, the same data type may have different The name. Even if the name is the same, the dimensions and other details may be different! Please always check the documentation!