How to insert, update, and delete data

The syntax for the INSERT statement

      INSERT INTO table-name [(column-list)] VALUES (value-list);
      

A statement that adds one row to a table

      INSERT INTO products (categoryID, productCode, productName, listPrice)
      VALUES (1, 'tele', 'Fender Telecaster', 599.00);
      

A statement that uses the MySQL NOW function to get the current date

      INSERT INTO orders (customerID, orderDate) 
      VALUES (1, NOW());
      

The syntax for the UPDATE statement

       UPDATE table-name 
       SET expression-1 [, expression-2] ... 
       WHERE selection-criteria;
      

A statement that updates a column in one row

      UPDATE products 
      SET productName = 'Ludwig 5-Piece Kit with Zildjian Cymbals' 
      WHERE productCode = 'ludwig';
      

A statement that updates a column in multiple rows

       UPDATE products SET listPrice = 299 WHERE categoryID = 1;
      

The syntax for the DELETE statement

      DELETE FROM table-name 
      WHERE selection-criteria;
      

A statement that deletes one row from a table

      DELETE FROM products 
      WHERE productID = 1;
      

A statement that deletes multiple rows from a table

      DELETE FROM products 
      WHERE listPrice > 200;
      

Description

Back