How to insert rows

The syntax of the INSERT statement

      INSERT INTO table_name [(column_list)] 
      VALUES (expression_1 [, expression_2]...)[, (expression_1 [, expression_2]...)]...
      

The table definition

      CREATE TABLE products ( 
        productID INT NOT NULL AUTO_INCREMENT
        categoryID INT NOT NULL,
        productCode VARCHAR(10) NOT NULL,
        productName VARCHAR(255) NOT NULL,
        description TEXT NOT NULL,
        listPrice DECIMAL(10,2) NOT NULL,
        discountPercent DECIMAL(10,2) NOT NULL DEFAULT 0.00,
        dateAdded DATETIMENOT NULL
      ); 
      

Add a single row without using a column list

      INSERT INTO products 
      VALUES (DEFAULT, 1, 'tele', 'Fender Telecaster', 'NA', '949.99', DEFAULT, NOW());
      

Add a single row using a column list

      INSERT INTO products (categoryID, productCode, productName, description, listPrice, dateAdded) 
      VALUES (1, 'tele', 'Fender Telecaster', 'NA', '949.99', NOW());
      

Add multiple rows

      INSERT INTO categories (categoryID, categoryName) 
      VALUES (4, 'Keyboards'), (5, 'Brass'), (6, 'Woodwind');
      

Description

Back