7

Is there a tool that allows me to create a sql populate script for a table using its current data?

6 Answers 6

10

Old question, but I got to the question before figuring out a way to solve the problem. So I'm just posting the method here in case it might help anyone else.

In SSMS:

  1. Right click on db -> "Tasks" -> "Generate Scripts..."
  2. Click "Next" and, at "Choose Objects" step, select the specific table
  3. Click "Next" and, at "Set Scription Options" step, click "Advanced"
  4. Set value for "Type of data to script", depending on what you need
  5. Continue to finish
Sign up to request clarification or add additional context in comments.

1 Comment

It's worth noting that this is almost the right answer. If you want to script out the INSERT statements needed to repopulate the database, you need to find the Types of data to script (the last entry in the first block of Advanced Options) as @Gustav mentions and pick Schema and data. That's buried just about as far down in the muck as possible.
2

Check out the SSMS Addins (for both SSMS 2005 and 2008):

alt text http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=SSMSAddins&DownloadId=48526

One of the tools included in the "DataScripter" which will script out INSERT statements for the table(s) you want to.

Comments

1

Maybe this is just enough for you: http://snipplr.com/view/12003/generate-insert-statements/

Comments

1

Another way to do it, even more convenient for developers, is within Visual Studio 2015 or 2017 (possibly earlier versions too):

  1. Main menu 'View' -> 'SQL Server Object Explorer'
  2. In the tree view connect to the Database of choice and select a table
  3. Right click on the table and select 'View Data' menu item
  4. In the [Data] window click on a 'Script' or 'Script to File' button

1 Comment

Visual Studio 2022 is almost identical, but for step for has an update here: 1. Main menu 'View' -> 'SQL Server Object Explorer' 2. In the tree view connect to the Database of choice and select a table 3. Right click on the table and select 'View Data' menu item 4. In the [SQL] menu, click on a 'Script' or 'Script to File' button
0

You could look at purchasing the Data Generator by Red-Gate which can create random sets of data based on your database schema.

Note: I'm not sure if the tool will generate data based on your current data though

1 Comment

No, it won't - it's a test data generator which will create new test data for your tables, based on some data repositories. But it definitely does not script out your current data in your tables.
0

You can do it with Database Publishing Wizard. Here is a tutorial: Generate Script with Data from Database – Database Publishing Wizard

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.