IT Milk: entry

The author published this entry on Wednesday 07 February, 2007 at 9:04 am. It's been filed in the Databasecategory

Bulk Insert in SQL

Here’s an overlooked extension of the INSERT command. I used to write separate INSERT statements for each record set. By appending additional executions, you can run multiple INSERT operations with a single command. (This multiple insert syntax does not work for MS SQL. Fernando Pires shows a workaround for MS SQL multiple insert.)

INSERT INTO exampleTable (name, origin, age)
VALUES
(’Daehee’, ‘Korea’, 18),
(’Wu Ming’, ‘Mongolia’, 45),
(’Leibniz’, ‘Holland’, 55),
(’Tyrone’, ‘New York’, 25);

Here’s an example of how to do it in MS SQL using Fernando’s workaround trick:

INSERT INTO dap5100_pizzeria (dap5100_prestaurant, dap5100_paddress, dap5100_pcity, dap5100_pstate, dap5100_pzip, dap5100_plarge, dap5100_pmedium, dap5100_psmall, dap5100_psub_6, dap5100_psub_12)
SELECT ‘Brutico’’s Restaurant’,'432 South Main Street’,'Old Forge’, ‘PA’, 18518, 8.50, 8.00, 7.75, 3.50, 5.99
UNION ALL
SELECT ‘Maxies Family Restaurant & Bar’,'320 South Keyser Avenue’,'Wilkes-Barre’,'PA’,18702,7.50,7.00,6.75,3.79,5.79
UNION ALL
SELECT ‘Arcaro & Genell’,'443 South Main Street’,'Old Forge’,'PA’,18518,9.00,8.50,8.25,3.88,5.88
UNION ALL
SELECT ‘Ghigiarelli’’s Restaurant’,'511 South Main Street’,'Hazleton’,'PA’,18201,9.50,9.00,8.75,3.99,5.99

Got Thoughts?

By all means share them, and start the conversation.

Leave Your Own Comment

You can follow any responses to this entry via its RSS comments feed. You can also leave a trackback if the inclination is there.

If you're looking for something specific then give the search form below a try:

RSS Wordpress Grady (theme) Valid XHTML Return to the Top ↑