Database Reference
In-Depth Information
▼
Input
CREATE TABLE orders
(
order_num int NOT NULL AUTO_INCREMENT,
order_date datetime NOT NULL ,
cust_id int NOT NULL ,
PRIMARY KEY (order_num)
) ENGINE=Aria;
▼
Analysis
This statement creates the
orders
table used throughout this topic.
orders
contains three columns: order number, order date, and the customer ID. All
three columns are required, and so each contains the keyword
NOT NULL
. This
prevents the insertion of columns with no value. If someone tries to insert no
value, an error will be returned, and the insertion will fail.
This next example creates a table with a mixture of
NULL
and
NOT NULL
columns:
▼
Input
CREATE TABLE vendors
(
vend_id int NOT NULL AUTO_INCREMENT,
vend_name char(50) NOT NULL ,
vend_address char(50) NULL ,
vend_city char(50) NULL ,
vend_state char(5) NULL ,
vend_zip char(10) NULL ,
vend_country char(50) NULL ,
PRIMARY KEY (vend_id)
) ENGINE=Aria;
▼
Analysis
This statement creates the
vendors
table used throughout this topic. The ven-
dor ID and vendor name columns are both required, and are, therefore, speci-
fied as
NOT NULL
. The five remaining columns all allow
NULL
values, and so
NOT NULL
is not specified.
NULL
is the default setting, so if
NOT NULL
is not
specified,
NULL
is assumed.