Mega Code Archive

 
Categories / MySQL / Insert Delete Update
 

Insert three rows together

/* mysql> Drop table CDs; Query OK, 0 rows affected (0.00 sec) mysql> CREATE TABLE CDs (     ->    CDID SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,     ->    CDName VARCHAR(50) NOT NULL,     ->    Copyright YEAR,     ->    NumberDisks TINYINT UNSIGNED NOT NULL DEFAULT 1,     ->    NumberInStock TINYINT UNSIGNED,     ->    NumberOnReserve TINYINT UNSIGNED NOT NULL,     ->    NumberAvailable TINYINT UNSIGNED NOT NULL,     ->    CDType VARCHAR(20),     ->    RowAdded TIMESTAMP     -> ); Query OK, 0 rows affected (0.04 sec) mysql> INSERT INTO CDs     -> (CDName, Copyright, NumberDisks, NumberInStock, NumberOnReserve, NumberAvailable, CDType)     -> VALUES     -> ('Variations', 1999, 1, 9, 0, NumberInStock-NumberOnReserve, 'Blues'),     -> ('The', 1990, 1, 14, 2, NumberInStock-NumberOnReserve, 'Popular'),     -> ('Shocked', 1988, 1, 6, 1, NumberInStock-NumberOnReserve, 'Folk-Rock'); Query OK, 3 rows affected (0.00 sec) Records: 3  Duplicates: 0  Warnings: 0 mysql> select * from CDs; +------+------------+-----------+-------------+---------------+-----------------+-----------------+-----------+---------------------+ | CDID | CDName     | Copyright | NumberDisks | NumberInStock | NumberOnReserve | NumberAvailable | CDType    | RowAdded            | +------+------------+-----------+-------------+---------------+-----------------+-----------------+-----------+---------------------+ |    1 | Variations |      1999 |           1 |             9 |               0 |               9 | Blues     | 2005-10-09 09:19:46 | |    2 | The        |      1990 |           1 |            14 |               2 |              12 | Popular   | 2005-10-09 09:19:46 | |    3 | Shocked    |      1988 |           1 |             6 |               1 |               5 | Folk-Rock | 2005-10-09 09:19:46 | +------+------------+-----------+-------------+---------------+-----------------+-----------------+-----------+---------------------+ 3 rows in set (0.01 sec) */ Drop table CDs; CREATE TABLE CDs (    CDID SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,    CDName VARCHAR(50) NOT NULL,    Copyright YEAR,    NumberDisks TINYINT UNSIGNED NOT NULL DEFAULT 1,    NumberInStock TINYINT UNSIGNED,    NumberOnReserve TINYINT UNSIGNED NOT NULL,    NumberAvailable TINYINT UNSIGNED NOT NULL,    CDType VARCHAR(20),    RowAdded TIMESTAMP ); INSERT INTO CDs  (CDName, Copyright, NumberDisks, NumberInStock, NumberOnReserve, NumberAvailable, CDType) VALUES  ('Variations', 1999, 1, 9, 0, NumberInStock-NumberOnReserve, 'Blues'), ('The', 1990, 1, 14, 2, NumberInStock-NumberOnReserve, 'Popular'), ('Shocked', 1988, 1, 6, 1, NumberInStock-NumberOnReserve, 'Folk-Rock'); select * from CDs;