DEV Community

Cover image for How to create table in SQL?
Damian Brdej
Damian Brdej

Posted on

3 1

How to create table in SQL?

To create table in SQL you have to use following syntax

CREATE TABLE table_name (
    column_1 datatype,
    column_2 datatype,
    column_3 datatype
);
Enter fullscreen mode Exit fullscreen mode

It's important to place comma after each column definition, and semicolon after whole statement.

Here's real life example:

CREATE TABLE users (
    id INT,
    name VARCHAR(255),
    surname VARCHAR(255),
    email VARCHAR(255),
    password VARCHAR(255)
);
Enter fullscreen mode Exit fullscreen mode

This statement creates table with 4 columns. First one is of type INT which means integer value. The other 4 columns are of type VARCHAR(255) which means TEXT with maximum length of 255. You can place any number in brackets to define length.

Top comments (0)

Retry later
Retry later