Mega Code Archive

 
Categories / MySQL / Insert Delete Update
 

In INSERT statement, the columns names are specified and only the values for those columns are included

mysql> 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.00 sec) mysql> mysql> mysql> INSERT LOW_PRIORITY INTO CDs (CDName, Copyright, NumberDisks,     -> NumberInStock, NumberOnReserve, NumberAvailable, CDType)     -> VALUES ('After the Rain: The Soft Sounds of Erik Satie',     -> 1995, DEFAULT, 13, 2, NumberInStock - NumberOnReserve, 'Classical'); Query OK, 1 row affected (0.00 sec) mysql> mysql> drop table CDs; Query OK, 0 rows affected (0.00 sec)