Generate INSERT scripts, the way they OUGHT to work!

by Grank February 12, 2008 14:06
One of the most irritating things about SSMS is that "Script Table As -> INSERT To" doesn't work like you'd want. Sometimes you get into a situation where just wanting to pass around some test data becomes irritatingly non-trivial...
Just want to generate a SQL script that you can run to insert a table's worth of data?
Here's a SQL script that generates a stored procedure to do just that!
Just run the script, and then EXEC sp_generate_inserts '[TableName]' to get a result set of properly formatted INSERT statements containing - imagine this - the actual data from the table!
There are some nice optional arguments that you can use as well; it'll automatically omit identity columns if you tell it to, and while computed columns will give you a headache, you can specifically exclude any column you want. Unfortunately, there are some spelling mistakes and other gotchas in the script, so you're best to see his original page for instructions on how to use it. Regardless, it's a nice time-saver to have lying around.

Tags: , ,

Comments

Add comment


(Will show your Gravatar icon)

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen | Modified by Mooglegiant

About The Author

I'm a software developer and musician in Edmonton, AB.  I write mostly web-based software, primarily on the Microsoft stack.  I have an MCPD and several MCTS, but I've only been at this whole developer thing for a few years, and the truth is that I'm still learning more than knowing.  So these are my adventures and experiments and some of it will probably be blatantly wrong...  Just warning ya.