Mega Code Archive

 
Categories / MySQL / Table Index
 

Column definition with modifiers

mysql> mysql> CREATE TABLE IF NOT EXISTS products     -> (     ->   id     INT             UNIQUE AUTO_INCREMENT,     ->   code   INT             NOT NULL,     ->   name   VARCHAR(25)     NOT NULL,     ->   qty    INT             DEFAULT 1,     ->   price  DECIMAL(6,2)    NOT NULL     -> ); Query OK, 0 rows affected (0.00 sec) mysql> mysql> # confirm the "products" table format mysql> EXPLAIN products; +-------+--------------+------+-----+---------+----------------+ | Field | Type         | Null | Key | Default | Extra          | +-------+--------------+------+-----+---------+----------------+ | id    | int(11)      | NO   | PRI | NULL    | auto_increment | | code  | int(11)      | NO   |     | NULL    |                | | name  | varchar(25)  | NO   |     | NULL    |                | | qty   | int(11)      | YES  |     | 1       |                | | price | decimal(6,2) | NO   |     | NULL    |                | +-------+--------------+------+-----+---------+----------------+ 5 rows in set (0.00 sec) mysql> mysql> # delete this sample table mysql> DROP TABLE products; Query OK, 0 rows affected (0.00 sec)