Create a new database table query
Here is an example of a new database table query in SQL:
CREATE TABLE customers (
id INT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
phone VARCHAR(20),
address VARCHAR(255),
city VARCHAR(50),
state VARCHAR(50),
zip VARCHAR(10),
country VARCHAR(50)
);
Let me explain what each part of this query does:
CREATE TABLE
: This is the command to create a new table in the database.customers
: This is the name of the table we are creating.(id, name, email, phone, address, city, state, zip, country)
: This is the list of columns (or fields) that we are defining in the table. Each column has a specific data type and constraints (e.g.NOT NULL
means that the column cannot be empty).id INT PRIMARY KEY
: This column is an integer (INT) and is defined as the primary key of the table. This means that each row in the table must have a unique value in this column.name VARCHAR(255) NOT NULL
: This column is a string (VARCHAR) with a maximum length of 255 characters, and is required to have a value (NOT NULL).- The rest of the columns have similar definitions.
This query creates a table called customers
with 9 columns: id
, name
, email
, phone
, address
, city
, state
, zip
, and country
. Each column has a specific data type and constraints to ensure that the data stored in the table is valid and consistent.
Note: The exact syntax may vary depending on the specific database management system you are using (e.g. MySQL, PostgreSQL, SQL Server, etc.).