SQL Data Types and Literals

SQL Data Types:

Every field or column in a table is given a data type when a table is defined. These data types describe the kind of information which can be stored in a column.

In SQL, this is done by assigning each field a data type that indicates the kind of values the field will contain. All the values in a given field must be of the same type.

There are commonly five types of data type in SQL:
i. CHAR
ii. VARCHAR
iii. NUMBER
iv. DATE
v. LONG

CHAR:

A column defined with a CHAR data type is allowed to store all types of characters which include letters both uppercase and lowercase letters, such as – A, B, …, Z and a, b, …, z and special characters like @, #, &, $, etc.

VARCHAR (size):

It is similar to CHAR but it can store variable sized string having a maximum length determined by ‘size’. The maximum value the ‘size’ can have is 2000 characters.

NUMBER (p, s):

It is used to store variable-length numeric data. The value of p determines the total number of digits possible to the left of the decimal point. The second value s determines the total number of digits possible to the right of the decimal point.

DATE:

This type of data is used to store date and time information. The default format is DD-MM-YY.

LONG:

This data type stores variable length character strings containing up to 2 gigabytes size. But LONG data type has some following limitations:

1. A table can’t have more than one LONG type of data field.
2. It can’t be indexed.
3. It can’t be used with SQL functions.
4. It can’t appear in WHERE GROUP BY, ORDER BY clauses.