Create table

SQL CREATE TABLE is a statement that is used to create a new table in a database. A table is a collection of data that is organized in rows and columns, similar to a spreadsheet. Each column represents a specific data type, while each row represents a unique record in the table.

Syntax

The basic syntax for creating a table using SQL is as follows:

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

The CREATE TABLE keyword is followed by the name of the table you want to create. This is followed by a list of column names and their respective data types. The data types specify the type of data that can be stored in each column, such as integer, string, date, or boolean.

Example

For example, suppose you want to create a table called “customers” to store customer information. You might use the following SQL statement:

CREATE TABLE customers (
   id INT PRIMARY KEY,
   name VARCHAR(50),
   email VARCHAR(50),
   phone VARCHAR(20),
   address VARCHAR(100),
   city VARCHAR(50),
   state VARCHAR(50),
   zip VARCHAR(10)
);

In this example, the table “customers” has eight columns: id, name, email, phone, address, city, state, and zip. The id column is specified as the primary key, which means it uniquely identifies each row in the table.

After executing the CREATE TABLE statement, the new table is added to the database, and you can start adding data to it using the SQL INSERT statement.

In summary, SQL CREATE TABLE is a fundamental statement in creating a new table with columns and data types specified. It provides a framework for organizing data, making it easier to store and retrieve information from a database.