Creating, altering, and dropping tables
Now that we know a little about how data is structured in a database, we can learn more about creating our own tables, making changes to them, and even how to delete them.
Using CREATE TABLE
We use the CREATE TABLE
command to create tables. For a basic database for an online store, we might have tables for customers, products, orders, product reviews, customer addresses, and more. We can create as many tables as we need, but as mentioned previously, we should give the design some thought so that we don't store duplicate or unused data. That said, don't worry about this too much, as we can always make changes later with the ALTER TABLE
command (see the Using ALTER TABLE section later in this chapter).
Using CREATE TABLE – basic syntax
The basic syntax of the CREATE TABLE
command is as follows:
CREATE TABLE table_name (<column_definitions>);
As with creating a database, we can add an IF NOT EXISTS
command before the table name to suppress the error...