SQL Data Types

Sql (pronounced like ‘sequel’ or spelled out as S-Q-L) is a structured query language designed for managing data within a relational database management system (RDBMS), and today we will be learning the various data types that can be stored in our database.

First we have numeric data; integers, decimals, and serials are all numeric. An integer is a whole number between roughly negative 2 billion and positive 2 billion and is given an ‘INT’ designation. There are also designations for small integers and large integers. A decimal is stored as DECIMAL and can be specified to customize it’s precision and scale (how many places it takes and how many digits after the decimal point). Another common numeric data type is the SERIAL which is an integer that is incremented based on data entered into the table — usually an ID is specified as a serial.

Next we have character data, mostly commonly designated as VARCHAR(n). This means the characters can vary depending on the content and have a maximum length of n.

To illustrate the above, here is the setup for a Products table with a column for each data type:

product_name VARCHAR(255),
SKU_number INT,
price DECIMAL(10, 2)

The Products table has an ID column with a numeric serial data type which increments for each product entered into the table (each item will have a unique ID, a product name column with varying characters up to 255 in length, a column for sku number with integer data up to about 2 billion places, and a price column which is a decimal with max length 10 and up to the hundredths decimal place.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.