How do you write the statement to create a table in SQL?

The basic format for creating a table in SQL is as follows:

CREATE TABLE table_name (
    column1 datatype constraint,
    column2 datatype constraint,
    ...
    columnN datatype constraint
);

In this case, table_name refers to the name of the table to be created, column1, column2, …, columnN are the names of the columns in the table, datatype is the data type of the columns, and constraint is an optional restriction.

Below is an example: create a table named customers with four columns – id, name, age, and email.

CREATE TABLE customers (
    id INT PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    age INT,
    email VARCHAR(100) UNIQUE
);

In the above example, the id column is designated as the primary key, the name column is set as not null, and the email column is specified as unique.

bannerAds