The Insert Statement

The INSERT statement allows you to add new records to a table. The basic syntax of the INSERT statement is the following:

INSERT INTO table_name (columnl, column2, ...) VALUES (valuel, value2, ...)

Use of the INSERT statement is very simple. You provide the name of the table and its columns that you'll be inserting data into, and then provide a list of values to be inserted. You must provide a value in the VALUES clause for each column named in the INSERT clause, and the values must appear in the same order as the column names they correspond to. Here's an example showing how to insert a new record into the Customers table:

INSERT INTO Customers (Company, [First Name], [Last Name], [Country/Region]) VALUES ('New Company', 'Rob', 'Bovey', 'USA')

Note that as with the WHERE clause of the SELECT statement, all of the string literals in the VALUES clause are surrounded by single quotes. This is the rule throughout SQL.

If you have provided values for every field in the table in your VALUES clause, the field list in the INSERT clause can be omitted. For example, if the four preceding fields were the only fields in the Customers table, you could simply use:

INSERT INTO Customers

0 0

Post a comment