Working with tables
Now we are going to create the necessary tables. First, we will run the USE
statement to set eshop as our default database. This allows us to avoid specifying the database name in each statement, as explained in Chapter 1, Installing MariaDB.
MariaDB [(none)]> USE eshop; Database changed
Then we can create our first table using CREATE TABLE
. This command specifies concepts that have not yet been discussed, such as table types and storage engines. The following example shows the syntax of the statement, but we will leave out the details for now. All these concepts will be made clear by the end of this chapter.
CREATE TABLE catalogue ( id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(50) NOT NULL, price DECIMAL(6, 2) NULL, quantity SMALLINT NOT NULL DEFAULT 0, description TEXT NOT NULL, PRIMARY KEY (id) ) ENGINE = InnoDB COMMENT 'Catalogue of products on sale';
While the details are probably a bit obscure, the general syntax of the statement...