Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

Multiple Inserts Expand / Collapse
Author
Message
Posted Monday, January 16, 2012 9:58 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 11:10 AM
Points: 31,279, Visits: 15,738
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
Post #1236977
Posted Monday, January 16, 2012 9:59 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, November 19, 2014 2:03 PM
Points: 2,278, Visits: 3,806
Good one Steve, Thank you.

Mohammed Moinudheen
Post #1236978
Posted Monday, January 16, 2012 10:27 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 5:27 PM
Points: 17,948, Visits: 15,946
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
Post #1236981
Posted Tuesday, January 17, 2012 4:03 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354, Visits: 1,299
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.
Post #1237078
Posted Tuesday, January 17, 2012 5:27 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Sunday, April 27, 2014 7:45 PM
Points: 1,589, Visits: 253
Good straight forward question. Thanks Steve.

http://brittcluff.blogspot.com/
Post #1237130
Posted Tuesday, January 17, 2012 7:00 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, November 19, 2014 3:56 PM
Points: 6,086, Visits: 8,354
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
Post #1237196
Posted Tuesday, January 17, 2012 7:24 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 6:31 PM
Points: 13,207, Visits: 12,688
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?


_______________________________________________________________

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 Moden's 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)
Post #1237208
Posted Tuesday, January 17, 2012 7:27 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 11:10 AM
Points: 31,279, Visits: 15,738
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
Post #1237213
Posted Tuesday, January 17, 2012 8:09 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Monday, November 10, 2014 3:37 AM
Points: 904, Visits: 1,491
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
Post #1237244
Posted Tuesday, January 17, 2012 9:25 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: 2 days ago @ 9:26 AM
Points: 1,802, Visits: 6,571
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
Post #1237317
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse