How to use SQL create table with example

What is table in database

The tables in the database store the data. A database may contain dozens or even hundreds of tables, depending on database schema or architecture as per the requirements of the project.

An SQL table consists of the columns and rows. Each column is also referred as a field. Each column or field has its own data type that specifies the type of data to be stored in that column.

For example, a table namely tbl_employee may contain emp_name, emp_age, emp_salary and joining_date fields. The field/column emp_name contains the characters to store employee name, emp_age can contain only numbers to store the employee’s age and emp_salary contains data with decimal points to store the employee’s salary.

Create table syntax

The syntax of creating a table involves Create table SQL command. The syntax is as follows:

Create Table table_name(

column1 date_type(length),

column2 date_type(length),

column3 date_type(length),

column4 date_type(length)

Primary key (column name(s))


So, the Create Table statement is followed by the table_name, that should be descriptive according to your project. Generally, the table names are started with tbl_ however you may have your own specifications for the table names. After the table name is an open parenthesis that contains the column names.

The column names should also be descriptive according to data it will store. For example, we have to store employees data that includes employee name, employee age and employee salary. As creating the names, we should assign descriptive column names e.g. emp_name, emp_age, emp_salary and joining_date.

For each field to be created, a data type must be specified in the create table command of SQL. This will be according to data this field will store. For example, the emp_name should be able to store the characters from A-Z in the capital or small letters. After that, emp_age should be able to store numbers without the decimals. Whereas emp_salary field should be able to store the numbers with the decimal point and joining_date should store the date of joining of the employees.

This is how we can create our example table, tbl_employee, with the above-mentioned fields along with its data types.

An example of creating a table

The following example shows how to use SQL create table statement. The example creates SQL table tbl_employee with four fields i.e. emp_name, emp_age, emp_salary, joining_date.

As we have gone through how to use the create table SQL command to create a simple tbl_employee table in our test_db database, it is time to go ahead with creating a table with the primary key.

Related – The Select statement | The delete statement

Was this article helpful?

Related Articles

Leave A Comment?