English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The CREATE TABLE command creates a new table in the database.
The following SQL creates a table named "Persons" that contains five columns: PersonID, LastName, FirstName, Address, and City:
CREATE TABLE Persons ( PersonID int, LastName varchar(255, FirstName varchar(255, Address varchar(255, City varchar(255) );
You can also use to create a copy of an existing table CREATE TABLE
The following SQL creates a new table called "TestTables" (a copy of the "Customers" table):
CREATE TABLE TestTable AS SELECT customername, contactname FROM customers;
The ALTER TABLE command adds, deletes, or modifies columns in the table.
The ALTER TABLE command also adds and removes various constraints in the table.
The following SQL adds a column named "Email" to the "Customers" table:
ALTER TABLE Customers ADD Email varchar(255);
The following SQL deletes the "Email" column from the "Customers" table:
ALTER TABLE Customers DROP COLUMN Email;
The DROP TABLE command will delete the table from the database.
The following SQL deletes the table "Shippers":
DROP TABLE Shippers;
Note:Be careful before deleting a table. Deleting a table will result in the loss of all information stored in the table!
The TRUNCATE TABLE command will delete the data in the table but will not delete the table itself.
The following SQL clears the "Categories" table:
TRUNCATE TABLE Categories;