Sql-server – EXPORT specific columns to INSERT statements

sql servert-sqlunit test

Is there a way to export specific columns and a fixed number of rows from a table to INSERT statements?

I am trying to generate these for unit testing based on a large production table so using something like "Generate Scripts" in SQL Server Management Studio is out of the question.

There are a few tools that might be able to do this, but something so trivial in MySQL should not be that complex in SQL Server (at least I would hope not).

Best Answer

Use Import/Export wizard and instead of exporting the entire table, choose sql to export specific rows and columns.

You can write sql like : select column1, column2 from Table1 where some_condition or if you don't care about specific data then you can use top command to extract any number of rows that you require.

Edit : Below are screenshots for Import export Wizard (Launch it from SSMS):

enter image description here

enter image description here

enter image description here

EDIT:

@Robin IN your situation, you can do 2 things -

  1. Go for something like Redgate's sql data generator that will generate test data -- OR --
  2. You can do a 1 time import of data as I suggested and then backup database and for your rest of testing you can just keep restoring the database from the backup (keeping in mind the data that you imported will not change). I cant think another way of doing what you want to achieve, so will keep this for others to answer ...