SQL Create Table Example

Amir
Amir
SQL Create Table Example

In this post we will look at how to create a table in SQL. Tables are the building blocks of relational databases. The database table is where all the data in a database is stored.

SQL Create Table Syntax

To create a table in SQL, we need to use the CREATE TABLE command.

1
2
3
4
5
6
CREATE TABLE table_name (
    column_name1 datatype,
    column_name2 datatype,
    column_name3 datatype,
   ....
);

column_names specify the name of the columns of the table.

The datatype specifies the type of the data the column can hold (e.g. integer, text, date, etc.).

SQL Create Table Example

1
2
3
4
5
6
7
CREATE TABLE employees (
    EmployeeID int,
    FirstName varchar(255),
    LastName varchar(255),
    Department varchar(255),
    JoiningDate DATE
)

The above code creates an empty table called “employees” with five columns.

In the specified columns, EmployeeID can only hold integer values - FirstName, LastName and Department columns can hold upto 255 characters.

JoiningDate column holds Date type.

See also