Creating Tables
Now that you know how to read data from tables, you will look at how to create new tables. There are two ways to do this—by creating blank tables or by using SELECT
queries.
Creating Blank Tables
To create a new blank table, you use the CREATE TABLE
statement. This statement takes the following structure:
CREATE TABLE {table_name} ( {column_name_1} {data_type_1} {column_constraint_1}, {column_name_2} {data_type_2} {column_constraint_2}, {column_name_3} {data_type_3} {column_constraint_3}, … {column_name_last} {data_type_last} {column_constraint_last} );
Here, {table_name}
is the name of the table, {column_name}
is the name of the column, {data_type}
is the data type of the column, and {column_constraint}
is one or more optional keywords giving special properties to the column. Before discussing how to use the CREATE TABLE
query, you should first learn about column data types and column constraints.