INSERT
The INSERT statement is used to
add rows to a table. There are two variations on how the INSERT statement
can be used. The first way allows you to add one new row to the table using
a set of specified values. The second way uses a SELECT query and allows you
to add multiple rows to a table. This variation is known as INSERT SELECT.
Inserting a single row
To insert a row into a table
you must specify the table name and a list of values to insert into the
table, as follows:
Example:
INSERT INTO
tblAddressBook
VALUES
('121',
'Stephen Smith',
'24',
'45 Great Eastern
Road, Glasgow',
'G1A 1BA',
'0123 456 7890',
'stephen@123abc.co.uk',
NULL)
This example will
insert a single row into a table. The values to store are provided in the
VALUES clause, and a value must be provided for every field. If there is no
value to enter for a field, NULL should be entered, as has been done above
for the MobilePhone field. This method of using INSERT is relatively simple
but in general should be avoided. This is because the order of the values
you have entered must match the order of the fields (also referred to as
columns) in the table. If the order of the columns changes then it will
break your SQL code.
Therefore, the following syntax
should be used, where both the field names and the values for those fields
are specified: |