Saturday, November 7, 2009

Insert Querie

INSERT

Syntax


INSERT INTO "table_name" ("column1", "column2", ...)VALUES ("value1", "value2", ...)

Assuming that we have a table that has the following structure,

Table Shop

and now we wish to insert one additional row into the table representing the sales data for Kumar on January 10, 1999. On that day, this store had $900 in sales. We will hence use the following SQL script:


INSERT INTO Shop (store_name, Sales, Date)
VALUES ('Kumar', 900, 'Jan-10-1999')


The second type of INSERT INTO allows us to insert multiple rows into a table. Unlike the previous example, where we insert a single row by specifying its values for all columns, we now use a SELECT statement to specify the data that we want to insert into the table.


INSERT INTO "table1" ("column1", "column2", ...)
SELECT "column3", "column4", ...
FROM "table2"

No comments:

Post a Comment