Basic Queries  «Prev 

Using the INSERT statement

It is possible to write the INSERT INTO statement in two forms.
The first form does not specify the column names where the data will be inserted, only their values:
INSERT INTO table_name
 VALUES (value1,value2,value3,...);
The second form specifies both the column names and the values to be inserted:
INSERT INTO table_name (column1,column2,column3,...)
 VALUES (value1,value2,value3,...);

INSERT statement begins by specifying the table name to insert the row into
INSERT INTO CustTable
INSERT statement begins by specifying the table name to insert the row into

You can optionally supply a list of column names in parentheses that will be assigned values in the new row. 
If the column names are omitted, the values in the column list will be entered in the order as the columns appear in the table.
(column1, column2)
You can optionally supply a list of column names in parentheses that will be assigned values in the new row. If the column names are omitted, the values in the column list will be entered in the order as the columns appear in the table. If you are including values for every field then it is not necessary to specify the data fields.

The VALUES clause contains the column values to assign when the row is inserted.
VALUES
The VALUES clause contains the column values to assign when the row is inserted.

A list of values is provided in parentheses. If column names were specified, then the values in the VALUE clause will be assigned to the columns in the order 
they were specified following INTO.
(value1, value2)
A list of values is provided in parentheses. If column names were specified, then the values in the VALUE clause will be assigned to the columns in the order they were specified following INTO.

The complete insert statement. Let us look at a statement using the BigBook.com database. 
The following statement inserts a row into the CustTable table. Data is assigned to only three columns: 1) customer number, 2) last name, and 3) first name.
INSERT INTO table
(column1, column2)
VALUES (value1, value2)
The complete insert statement. Let us look at a statement using the BigBook.com database. The following statement inserts a row into the CustTable table. Data is assigned to only three columns: 1) customer number, 2) last name, and 3) first name.

CustTable table is specified
8
CustTable table is specified

Then, you add the column names which will be assigned values
INSERT INTO CustTable
(CustNo, LName, FName)
Then, you add the column names which will be assigned values

Finally, the values are added. Now you have the complete statement to insert a row.
INSERT INTO CustTable
(CustNO, LName, FName)
VALUES
('0000000010', 'Rogers', 'William')
Finally, the values are added. Now you have the complete statement to insert a row.