First, we need to cover the various data types available (see Table 3-1). Data types are like variable types. In some languages, you have strings, integers, floating-point numbers, big integers, characters, and so on. The same holds true for database data types: There are different data descriptors for different types of data. Every column in the database is for storing a particular kind of data: a column for storing last names would be of type 'varchar', a column for storing birthdates should be of type 'date', and so on. This helps the database store the information more efficiently and helps the programmer know what kind of data to expect.
Name | Type | Description | Notes |
---|---|---|---|
INT | Numeric | Signed four-byte integer | -2147483648 to +2147483647 |
SMALLINT | Numeric | Signed two-byte integer | -32768 to +32767 |
REAL | Numeric | Variable precision | 6 decimal digits precision |
CHAR(n) | Character | Fixed-length char string | Holds n characters |
VARCHAR(n) | Character | Variable-length char string | Holds up to n characters |
BLOB | Binary | Binary Large OBject | For storing large binary data |
Name | Type | Description | Notes |
DATE | Date | Date storage | Ex. YYYY-MM-DD |
TIME | Time | Time storage | Ex. HH:MM:SS |
TIMESTAMP | Date/Time | Date & Time storage | Ex. YYYY-MM-DD HH:MM:SS |