• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 4. Using SQL > The INSERT Statement

The INSERT Statement

You use the INSERT statement to add a new record to your table. To alter an existing record, you use the UPDATE statement (see below).

Unfortunately, it’s not possible to actually type an INSERT or UPDATE statement directly into Dreamweaver. But when you insert or alter a record using Dreamweaver’s Record Insertion Form (see Adding Database Records in Chapter 8), Dreamweaver is generating these statements behind the scenes. So it’s a good idea to make sure you’re familiar with them and how they function.

The basic format for the INSERT statement is:

INSERT into table_name
(column1, column2,...columnN)
values (value1, value2, ...valueN);

We’ve specified the table into which we want to insert a record. Then we specified the columns for which we want to add data. Finally, we specified the data we want to put into those columns in the same order we specified the names.

You can list the columns you want to add in any order, but you must list the values in the same order, or they will end up in the wrong place. (This can also cause errors when the browser requests the data.) If any of your values is a string, you must to enclose it in single quotes.

To add a new product to our catalog, the statement would look a bit different:

INSERT into product_catalog
(product_ID, product_name,
values (99, 'Fish Food', 'Healthy food for your little fishies!');

Here, we are adding a record to the table “product_catalog.” For the new record, the product_ID is 99, the product_name is “Fish Food,” and the contents of the description field are “Healthy food for your fishies!

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint