Database Reference
In-Depth Information
Note
Just the Basics MariaDB supports a vast array of table creation options, far more
than a single chapter can do justice to. In this chapter we cover the basics, just so you
can get a feel for what's involved in table creation, and so that the accompanying table
creation scripts make sense. To learn more about all that
CREATE TABLE
can do,
consult the MariaDB documentation.
To create
a table using
CREATE TABLE
, you must specify the following infor-
mation:
The name of the new table specified after the keywords
CREATE
TABLE
.
■
The name and definition of the table columns separated by commas.
■
The
CREATE TABLE
statement may also include other keywords and options,
but at a minimum you need the table name and column details. The follow-
ing MariaDB SQL statement creates the
customers
table used throughout
this topic:
▼
Input
CREATE TABLE customers
(
cust_id int NOT NULL AUTO_INCREMENT,
cust_name char(50) NOT NULL ,
cust_address char(50) NULL ,
cust_city char(50) NULL ,
cust_state char(5) NULL ,
cust_zip char(10) NULL ,
cust_country char(50) NULL ,
cust_contact char(50) NULL ,
cust_email char(255) NULL ,
PRIMARY KEY (cust_id)
) ENGINE=Aria;
▼
Analysis
As you can see in the preceding statement, the table name is specified immedi-
ately following the
CREATE TABLE
keywords. The actual table definition (all
the columns) is enclosed within parentheses. The columns themselves are
separated by commas. This particular table is made up of nine columns.