Tuesday, July 16, 2013

Generating data script for table using conditions in SQL Server

Problem Statement

Generate data script from table where records are in millions but we need data script for few records only.


Create a temporary table with the same structure as of the main table and insert data in the temporary table using the condition for filtering the records for which data script is required.
Or this can be done by:
select * into tmpMyTable from MyTable where <your condition(s)>

Now you can use the normal generate script method for this temp table and chose the option "Data Only" for getting the data script.
In the end drop the temp table.

Simple solution, works fine :)

No comments: