Database Reference
In-Depth Information
INSERT INTO books
( author , title )
VALUES ( 'Evelyn Waugh' , 'Brideshead Revisited' );
Note that this example lists just two columns within parentheses. It's also significant that
the statement lists them in a different order. The list of values must match the order of the
list of columns. For the third column (i.e., year ) of this table, the default value will be in-
serted.
When you have many rows of data to insert into the same table, it can be more efficient to
insert all of the rows in one SQL statement. To do this, you need to use a slightly different
syntax for the INSERT statement. Just add more sets of values in parentheses, each set
separated by a comma. Here's an example of this:
INSERT INTO books
( title , author , year )
VALUES ( 'Visitation of Spirits' , 'Randall Kenan' , '1989' ),
( 'Heart of Darkness' , 'Joseph Conrad' , '1902' ),
( 'The Idiot' , 'Fyodor Dostoevsky' , '1871' );
This SQL statement enters three rows of data into the books table. Notice that the set of
column names and the VALUES keyword appear only once. Almost all SQL statements
allow only one instance of each clause (the VALUES clause in this case), although that
clause may contain multiple items and lists as it doeshere.
Search WWH ::




Custom Search