This page shows information on basic use of CREATE TABLE. However, there are many options possible with this statement. Below are links to pages with more details on each:
This is one of the primary MySQL statements that a MySQL developer will use when first setting up a database. It's used to create MySQL tables, to which data will later be added.
hits past month: 13 ; last updated: may 4, 2009 - 2:34am ; parent: Database & Table Schema StatementsCREATE [TEMPORARY] TABLE [IF NOT EXISTS] table
{[(definition)][options]|[[AS] SELECT...]|[LIKE table]}
Use this statement to create a new table within a database. This statement has many clauses and options. However, when creating a basic table, you can omit most of them. The TEMPORARY keyword is used to create a temporary table that can be accessed only by the current connection thread and is not accessible by other users. The IF NOT EXISTS flag is used to suppress error messages caused by attempting to create a table by the same name as an existing one. After the table name is given, either the table definition is given (i.e., a list of columns and their data types) along with table options or properties, or a table can be created based on another table. See these related pages, which describe how to:
Here is a simple example of how you can use the CREATE TABLE statement:
CREATE TABLE clients (client_id INT AUTO_INCREMENT PRIMARY KEY, client_name VARCHAR(75), telephone CHAR(15));
This creates a table with three columns. The first column is called client_id and may contain integers. It will be incremented automatically as records are created. It will also be the primary key field for records, which means that no duplicates are allowed and that the rows will be indexed based on this column. The second column, client_name is a variable-width, character-type column with a maximum width of 75 characters. The third column is called telephone and is a fixed-width, character-type column with a minimum and maximum width of 15 characters. To see the results of this statement, you can use the DESCRIBE statement. There are many column data types.