SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Multiple Inserts


Multiple Inserts

Author
Message
Steve Jones
Steve Jones
SSC Guru
SSC Guru (250K reputation)SSC Guru (250K reputation)SSC Guru (250K reputation)SSC Guru (250K reputation)SSC Guru (250K reputation)SSC Guru (250K reputation)SSC Guru (250K reputation)SSC Guru (250K reputation)

Group: Administrators
Points: 250100 Visits: 19813
Comments posted to this topic are about the item Multiple Inserts

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
M&M
M&M
SSCrazy Eights
SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)SSCrazy Eights (9.7K reputation)

Group: General Forum Members
Points: 9734 Visits: 3916
Good one Steve, Thank you.

M&M
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (111K reputation)SSC Guru (111K reputation)SSC Guru (111K reputation)SSC Guru (111K reputation)SSC Guru (111K reputation)SSC Guru (111K reputation)SSC Guru (111K reputation)SSC Guru (111K reputation)

Group: General Forum Members
Points: 111624 Visits: 18624
Straight up question.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

cengland0
cengland0
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2820 Visits: 1300
I love that insert method and MySQL has had it available for so long. Unfortunately, it took Microsoft ages to add that feature. Too bad it wasn't available in the earlier versions of SQL Server 2000 and 2005. Because of that, I will not use that insert method because (as I've stated in other threads) I like to make my SQL portable. If I built it and it works on 2008 only, I couldn't put the same code on a 2005 server.

Some of you might say that I shouldn't worry about the portability and just program for what I have available (for performance reasons) but I've had to change servers so many times I already have experience with wasting time reprogramming incompatible code. I don't want to subject myself to that in the future. My minimum requirement is SQL Server 2005. If it doesn't work in 2000, I don't care because I don't know of any servers in my business still on that platform.
Britt Cluff
Britt Cluff
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2903 Visits: 253
Good straight forward question. Thanks Steve.

http://brittcluff.blogspot.com/
Hugo Kornelis
Hugo Kornelis
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27316 Visits: 12736
A good question, and it's hard to see how anbody could contest the correct answer.

Although in the spirit of nitpicking, I could argue that the format one should use would include the column list in the INSERT statement. And the semicolon statement terminator, that in a future version will no longer be optional.

INSERT dbo.mytable (Column1, Column2) VALUES ('Test', 'Test2'), ('Test3', 'Test4'), ('test5', 'test6');

EDIT: Removed the color tag after a few failed attempts to use it - I hope just using bold text emphasises the changes sufficiently.
EDIT: Added back the color tag after Paul told me what I did wrong.


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Sean Lange
Sean Lange
SSC Guru
SSC Guru (113K reputation)SSC Guru (113K reputation)SSC Guru (113K reputation)SSC Guru (113K reputation)SSC Guru (113K reputation)SSC Guru (113K reputation)SSC Guru (113K reputation)SSC Guru (113K reputation)

Group: General Forum Members
Points: 113566 Visits: 18297
Hugo Kornelis (1/17/2012)
A good question, and it's hard to see how anbody could contest the correct answer.

Although in the spirit of nitpicking, I could argue that the format one should use would include the column list in the INSERT statement. And the semicolon statement terminator, that in a future version will no longer be optional.

INSERT dbo.mytable (Column1, Column2) VALUES ('Test', 'Test2'), ('Test3', 'Test4'), ('test5', 'test6');

EDIT: Removed the color tag after a few failed attempts to use it - I hope just using bold text emphasises the changes sufficiently.


Actually if you wanted to nitpick you missed it. Including column names is best practice which doesn't mean you should use it. The correct answer is also the ONLY answer with valid syntax. Maybe your nitpicking can be the wording. Which one of these has the correct syntax? :-D

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Steve Jones
Steve Jones
SSC Guru
SSC Guru (250K reputation)SSC Guru (250K reputation)SSC Guru (250K reputation)SSC Guru (250K reputation)SSC Guru (250K reputation)SSC Guru (250K reputation)SSC Guru (250K reputation)SSC Guru (250K reputation)

Group: Administrators
Points: 250100 Visits: 19813
Hugo Kornelis (1/17/2012)
A good question, and it's hard to see how anbody could contest the correct answer.

Although in the spirit of nitpicking, I could argue that the format one should use would include the column list in the INSERT statement. And the semicolon statement terminator, that in a future version will no longer be optional.


Picky, picky.

Yes, I should have the semi-colon in there. I do like to show code the way I'd want it written in production, and the semi-colon is one I'm struggling to remember as I write since it's an old habit to forgo it.

The columns, it's a good idea, and I've gotten slightly lazy over the years with this.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Andre Guerreiro
Andre Guerreiro
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3377 Visits: 1515
Easy and straight-forward question.
Thank you.

And when I need to use something similar in MSSQL 2000 or 2005 I write this:


INSERT INTO dbo.Table(Column1, Column2)
SELECT 'Value1', 'Value2' UNION ALL
SELECT 'Value3', 'Value4' UNION ALL
SELECT 'Value5', 'Value6';



Best regards,

Andre Guerreiro Neto

Database Analyst
http://www.softplan.com.br
MCITPx1/MCTSx2/MCSE/MCSA
Toreador
Toreador
SSCertifiable
SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)

Group: General Forum Members
Points: 5010 Visits: 8188
Hugo Kornelis (1/17/2012)
A good question, and it's hard to see how anbody could contest the correct answer.


How long before someone complains that the correct answer is an error message saying there's no such table as my table ;-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search