SQL INSERT Statement

The syntax for the INSERT statement is:

INSERT INTO table
(column-1, column-2, … column-n)
VALUES
(value-1, value-2, … value-n);


A simple example:

INSERT INTO suppliers
(supplier_id, supplier_name)
VALUES
(24553, ‘IBM’);


More complex inserts can be performed:

INSERT INTO suppliers
(supplier_id, supplier_name)
SELECT account_no, name
FROM customers
WHERE city = ‘Newark’;

By placing a “select” in the insert statement, you can perform multiples inserts quickly.

With
this type of insert, you may wish to check for the number of rows being
inserted. You can determine the number of rows that will be inserted by
running the following SQL statement before performing the insert.

SELECT count(*)
FROM customers
WHERE city = ‘Newark’;

See here for more details.




About this entry