SQL > Data Definition Language (DDL) > Create Table Statement

In the CREATE TABLE page, we mentioned that it is necessary to specify the data type for each column when we create a table. So exactly what are the different types of data we can store in a table? While it is beyond the scope of this tutorial to list the exact data types supported by all the major database tools, we can nevertheless group the different data types into the following categories:

SQL data types define the kind of data a column can store. They fall into four main categories: Numeric, Character String, Date/Datetime, and Binary — each supporting different operations and SQL functions.
  • Numeric
  • Character String
  • Date/Datetime
  • Binary

    Numeric

    This type of data stores numerical values. Data types that fall in this category include Integer, Float, Real, Numeric, or Decimal. Common functions that operate on this type of data include COUNT, SUM, MAX, MIN, and AVG.

    Character String

    This type of data stores character values. The two common types are CHAR(n) and VARCHAR(n). The CHAR(n) data type holds n characters, padded with spaces at the end if needed. VARCHAR stands for Varying Char, meaning that the length of the field can vary. For example, a VARCHAR(10) data type holds up to 10 characters. But if data is only 8 characters long, then it will only store 8 characters. Common functions that operate on this type of data are discussed in String Functions.

    Binary

    This type of data allows us to store binary objects in a database table. Data types that fall in this category include Blob, Binary, and Raw. Please note that a field of binary data type cannot be used as keys, and one cannot build a table index using a binary column.

    Date/Datetime

    This type of data allows us to store date or datetime in a database table. Different databases have very different implementations of the date / datetime data type. Common functions that operate on this type of data are discussed in Date Functions.

    Frequently Asked Questions

    What are the main SQL data types?
    SQL data types fall into four main categories: Numeric (INTEGER, FLOAT, REAL, DECIMAL), Character String (CHAR, VARCHAR), Date/Datetime, and Binary (BLOB, BINARY, RAW). The exact types supported vary by database system (MySQL, PostgreSQL, SQL Server, Oracle, etc.).
    What is the difference between CHAR and VARCHAR in SQL?
    CHAR(n) stores exactly n characters and pads shorter values with spaces, making it fixed-length. VARCHAR(n) stores up to n characters without padding, using only as much space as the actual data requires. VARCHAR is generally preferred for variable-length text.
    Can you use a binary column as a primary key in SQL?
    No. Binary data type columns (BLOB, BINARY, RAW) cannot serve as primary keys or be used to build table indexes. For key columns, use numeric types (INT) or fixed-length character types (CHAR).
    Which SQL aggregate functions work with numeric data types?
    The main aggregate functions for numeric data are COUNT (count rows), SUM (add values), MAX (find the maximum), MIN (find the minimum), and AVG (calculate the average). These operate on numeric columns in a SELECT query.


    Next: SQL View

    This page was last updated on March 19, 2026.




    Copyright © 2026   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact