Click here to monitor SSC

Rodney

The Holy Scrolling NO WAY Gold Nugget (Script Data) SSMS 2008

Published Monday, December 08, 2008 8:21 PM

Tonight, I set about blogging about something I thought was interesting, funny and marginally useful (IFmU)...or wait...funny, useful and marginally interesting (FUmI). Part of the blog post I had envisioned would be to create a database, it's objects and data to reproduce the FUmI that I wanted to impart. However...as I was creating said database I stumbled upon a new feature in SQL Server Management Studio that caused a gasping pause followed by a "No FUmIng WAY!" So, apparently no one told me that SSMS now includes an option when scripting databases to script the data too. I had to make sure so naturally I searched and despite a few obscure blog posts, there was little mention.  Fair to say though, that several have already discovered this gold nugget...but I wanted to post it here for the ones who may not know.

In SSMS 2008, right click a database and select Tasks\Generate Scripts to initiate the Script Wizard. On the third page of the wizard, there it is if you scroll down..."Script Data".  I scrolled thinking, 'Wow, it would be so...um...yeah cool if I saw something like ‘script data’”.  And boom, there it was just like my first ever use of single quotes in double quotes like at the end of the last sentence.

So, yes, it does exist. And here is a sample of the INSERT statements created. For the record this works with 2008 and 2005 databases. I have not tried 2000 but I am hopeful.  Also, it is smart enough to batch the transactions each several thousand rows.

INSERT [dbo].[IN] ([BETWEEN], [LIKE]) VALUES (N'AVG ', NULL)

INSERT [dbo].[IN] ([BETWEEN], [LIKE]) VALUES (N'ABS ', NULL)

INSERT [dbo].[IN] ([BETWEEN], [LIKE]) VALUES (N'AND ', NULL)

INSERT [dbo].[IN] ([BETWEEN], [LIKE]) VALUES (N'BACKUP ', NULL)

GO

print 'Processed 2800 total records'

I saw several articles lately talking about a new feature in SQL Server 2008 about how we can now declare and assign variables in line without a separate SET assignment. That was in the marginally interesting (mI) bracket for me prior. That feature now falls into the "whoopie freakin do" category comparatively.

And those of you wondering about these crazy inserts, please read the subsequent blog post.  

by Rodney
Attachment(s): scriptdata.jpg

Comments

 

jerryhung said:

Cool, I did not know that and I thought I know most 2008 new features already

Given, I still use SSMS Tools Pack to generate data inserts (can customize batch size)
It's a right-click away on any table you select, much easier
December 9, 2008 12:40 PM
 

Rodney said:

Thanks for the tip, jerryhung. Well played.
Rodney
December 9, 2008 1:28 PM
You need to sign in to comment on this blog
<December 2008>
SuMoTuWeThFrSa
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910
How to Kill a Company in One Step or Save it in Three
 The majority of companies that suffer a major data loss subsequently go out of business. Wesley David... Read more...

Migrating from OCS 2007 R2 to Lync: Part 4
 Having migrated the rest of our users and legacy resources across and started getting ready to... Read more...

Automated Script-generation with Powershell and SMO
 In the first of a series of articles on automating the process of building, modifying and copying SQL... Read more...

Seth Godin: Big in the IT Business
 Seth Godin has transformed our understanding of marketing in IT. He invented the concept of 'permission... Read more...

Using SQL Test Database Unit Testing with TeamCity Continuous Integration
 With database applications, the process of test and integration can be frustratingly slow because so... Read more...