Creating Tables
Now that we know how to read data from tables, we will now look at how to create new tables. There are fundamentally two ways to create tables: creating blank tables or using SELECT
queries.
Creating Blank Tables
To create a new blank table, we 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 we discuss how to use the CREATE TABLE
query, we will first discuss column constraints.
Column Constraints
Column constraints are keywords that...