Database
Learn SQLTable of Contents
SQL Data Types
SQL Character and Numeric Data Type
SQL Date & Time Data Type
Implementation-Specific Data TypesSQL Character and Numeric Data Type
Character
character(n)
This and its alias, char(n), allow text strings of length n. Strings of less than length n will be padded with spaces on the right-hand side up to length n. An example of this behavior is shown in Figure 2.

character varying(n)
Also known as varchar(n), this data type allows text strings of any length up to n characters. These strings are not padded.
Some database systems implement this as simply varchar, which does not require a maximum length to be specified. A varchar field without a specified maximum length will accept text strings of (ideally) unlimited length. This is similar to the non-standard text data type, which is discussed later in this article.
Numeric
smallint
Also called int2, this data type represents a signed, two-byte integer. These may range in value from -32,768 to 32,767.
integer
This and its aliases, int and int4, represent signed, four-byte integers. These may range in value from -2,147,483,648 to 2,147,483,647 and are the most commonly used integer data type.
real
Also called float4, this represents a four-byte floating point number. This has less precision than a double precision value and can represent, approximately, -3.40e38 to -1.18e-38, zero, and 1.18e-38 to 3.40e38.
double precision
Also known as float8 and simply float, these eight-byte floating point numbers are much more precise than those represented by real. These are also more computationally expensive to use in calculations, and they require more storage than real values. Most applications also do not require the precision of double precision values. These values can represent, approximately, -1.79e308 to -2.23e-308, zero, and 2.23e-308 to 1.79e308.
numeric(p, s)
This value and its synonyms, decimal(p, s) and dec(p, s), represent exact integer or decimal numbers with arbitrary precision p and scale s. To be clear, p is the maximum number of digits that can be stored in the entire value, and s is the maximum number of digits that can be stored to the right of the decimal point. Thus, 0 ≤ s ≤ p. These data types are commonly used to precisely store monetary values.
Next Page: SQL Date & Time Data Type
