January 16, 2012 at 9:58 pm
Comments posted to this topic are about the item Multiple Inserts
January 16, 2012 at 9:59 pm
Good one Steve, Thank you.
M&M
January 16, 2012 at 10:27 pm
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[/url]
Learn Extended Events
January 17, 2012 at 4:03 am
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.
January 17, 2012 at 5:27 am
Good straight forward question. Thanks Steve.
http://brittcluff.blogspot.com/
January 17, 2012 at 7:00 am
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.
January 17, 2012 at 7:24 am
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 17, 2012 at 7:27 am
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.
January 17, 2012 at 8:09 am
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
January 17, 2012 at 9:25 am
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 😉
January 17, 2012 at 9:29 am
I agree with cengland0 about portability. You never know where your code will end up running, even if it is a secured ("closed"?) environment. As a former Tech Support Analyst, we got several headaches when new versions of SQL Server were released because of code deprecation and incompatibility, so I wave the "As Standard As Possible" flag.
Cheers,
January 17, 2012 at 10:41 am
tks Steve.
January 17, 2012 at 11:36 am
Toreador (1/17/2012)
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 😉
Not me, but about those column names ... certainly it's not good design practice to use such generic column names. :hehe:
[font="Verdana"]Please don't go. The drones need you. They look up to you.[/font]
Connect to me on LinkedIn
January 17, 2012 at 2:07 pm
Hugo Kornelis (1/17/2012)
EDIT: Removed the color tag after a few failed attempts to use it - I hope just using bold text emphasises the changes sufficiently.
Like this...? (the stupid trick here is to put double-quotes around the hex colour value *and* the leading # sign. Awesome.)
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
HugoHugoHugoHugoHugoHugo
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
January 17, 2012 at 4:40 pm
SQL Kiwi (1/17/2012)
Like this...? (the stupid trick here is to put double-quotes around the hex colour value *and* the leading # sign. Awesome.)
Thanks, Paul. I missed the double-quotes.
I have now edited my post to show the missing bits in red.
Viewing 15 posts - 1 through 15 (of 21 total)
You must be logged in to reply to this topic. Login to reply