SQL CREATE TABLE

SQL CREATE TABLE

The CREATE TABLE statement is used to create a new table in a database. Tables are the fundamental structures for storing data in a relational database.


Syntax

When you create a table, you must define its columns and the type of data each column will hold.

CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
);

Common data types include INT (for integers), VARCHAR(size) (for text), DATE, and DECIMAL(precision, scale).


Example

The following SQL statement creates a table called "Persons" that will store a person's ID, name, and address information.

CREATE TABLE Example

CREATE TABLE Persons (
    PersonID int,
    LastName varchar(255),
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255)
);

After this statement is executed, a new empty table named Persons will exist in the database, ready for you to INSERT data into it.