SQL's INSERT Statement
- Adds rows to a table.
- Basic syntax:
INSERT INTO table_name [(column_list)] VALUES (value1, value2, ...)
- Perl syntax:
Unlike ordinary usage of quotation marks in Perl,
the values in an insert statement must be single quoted,
even if they are scalar variables.
This causes them to be interpolated properly.
Without them, an "Invalid Bracketing" error occurs.
- Example:
INSERT INTO title (name, title_id, edition, price) VALUES ('Romeo and Juliet', 3725, 11, 12.50)
- Example:
INSERT INTO title VALUES (3725, 'Romeo and Juliet', 12.50, 11)
- If you omit the column list, the values must be in the order
in which they were created in the table.
- Enclose values with single quotes when they
contain spaces or commas.
- Example of sending the SQL statement to the database:
$sth = $dbh->prepare(qq{ INSERT INTO title (name, price, edition) VALUES ('$name', '$price', '$edition')})
Review
When the values come from Perl variables, must they be quoted?
Review
Which kind of quotation marks should be used when passing
an INSERT statement to the ->prepare method?
Dan Keller Technical Services © 2000