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)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay