|
In the previous sections, we have seen how to query information from tables. But how do these rows of data get into these tables in the first place? This is what this and the next section, covering the INSERT INTO statement, as well as the following section, covering tbe UPDATE statement, are about.
In SQL, there are basically two ways to INSERT data into a table: One is to insert it one row at a time, the other is to insert multiple rows at a time. In this section, we'll take a look at the first case:
The syntax for inserting data into a table one row at a time is as follows:
INSERT INTO "table_name" ("column1", "column2", ...)
VALUES ("value1", "value2", ...)
Assuming that we have a table that has the following structure,
Table Store_Information
| Column Name | Data Type |
| store_name | char(50) |
| Sales | float |
| Date | datetime |
and now we wish to insert one additional row into the table representing the sales data for Los Angeles on January 10, 1999. On that day, this store had $900 in sales. We will hence use the following SQL script:
INSERT INTO Store_Information (store_name, Sales, Date)
VALUES ('Los Angeles', 900, 'Jan-10-1999');
Next: SQL INSERT INTO SELECT
|
| Copyright © 2013 1keydata.com All Rights Reserved.
Privacy Policy |
|