tags:

views:

2547

answers:

11

The only thing I don't have an automated tool for when working with SQL Server is a program that can create INSERT INTO scripts. I don't desperately need it so I'm not going to spend money on it. I'm just wondering if there is anything out there that can be used to generate INSERT INTO scripts given an existing database without spending lots of money.

I've searched through SQL Server Management Studio Express with no luck in finding such a feature. If it exists in SSMSE then I've never found it.

A: 

Why don't you just write some code to generate the statement?

Pyrolistical
+1, that's a valid question. Code to generate code is a reasonable approach here.
Ian Varley
Writing code when code is already written and tested is unnecessarily costly, even if fun.
ProfK
+6  A: 

This web site has many useful scripts including generating inserts.

You can utilise sp_msforeachtable with it to generate for an entire DB.

Mitch Wheat
I used that script today =)
StingyJack
But had to find an amended one that worked with SQL2005+...http://www.benzzon.se/forum/printer_friendly_posts.asp?TID=86
StingyJack
I've loved that site for the past year!
Jarrod Dixon
I can not imagine my life without sp_generate_inserts...
Vnuk
A: 

Not sure about the express edition but the normal edition of SMSS, you can right click on a tab and script the table as select, insert update to a new window, clipboard or file.

You could also look at MyGeneration or CodeSmith as code generators. I believe they are free and should have soem templates that given a DB will create a bunch of stored procs for you.

JoshBerke
A: 

In SQL Server Management Studio Express, right click on a table in the Object Explorer sidebar and select "Script Table As / INSERT To / New Query Editor Window".

AJ
That doesn't script the contents of the table.
ProfK
A: 

It is pretty straightforward (and low cost) to write a stored procedure or function to generate insert (or other DML) scripts using the information available in the information_schema views.

cmsjr
+4  A: 

Theres a stored proc called "sp_generateinserts" you can google for it. It will take a table and convert it into insert statements.

Jobo
+1  A: 

you can also use this add-in for SSMS that provides this functionality: http://www.ssmstoolspack.com/

it also provide other useful features as well.

Mladen Prajdic
A: 

Not many people know this but you can use sub sonic (http://subsonicproject.com/) to script both the database structure and the data inside it.

The commands are pretty simple ( i use the command line ) eg.

sonic.exe scriptdata /server testserver /db testdb .

This will script all the data into insert statements for you :) , nice and clean.You and also hook this into visual studio if you want to make it easier and not use the command line.

RC1140
A: 

If you're just looking to insert test data, and have fewer than 64K rows to insert, you could use Excel (that's what I do).

For example, if you put values in cells A1, B1, and C1, then entered the following formula in D1, you'd get a usable insert statement:

="INSERT INTO TEST (col1, col2, col3) VALUES ("&a1&","&b1&","&c1&");"

Then just fill down and you can modify the data any time you want.

Jess
A: 

Try http://www.sqlscripter.com to generate insert, update and delete DML scripts.

John
A: 

Hey mate,
Try DBSourceTools. http://dbsourcetools.codeplex.com
It has a facility to generate insert scripts for any table in your database.

blorkfish