Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Generate Scripts - Data SPECIFIC & Schema

Author  Topic 

mikeallenbrown
Yak Posting Veteran

72 Posts

Posted - 2015-04-09 : 15:40:46
I see how I can generate a CREATE TO script file with a table's data & schema. Is there a way to generate this file but only specific rows?? ...like generate data & schema where clientid = 5001?

Thanks

Mike Brown
ITOT Solutions, Inc.
SQL Server 2012
Alpha Five v3 (12)

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-04-10 : 08:39:10
just one table?

1. script as create table to file
2. write your own query to generate the insert into statement(s) and add to the file from the first step.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2015-04-12 : 07:45:51
Couple of other ways:

Copy the database and delete everying which is not clientid = 5001

If we are talking a lot of data then the INSERT script will be slow. Alternative might be to create a new database and:

SELECT *
INTO NewDatabase.dbo.MyTable
FROM MyTable
WHERE clientid = 5001

Or, again if a lot of rows, export using XML and write a routine to import from XML. Or could use SSIS.
Go to Top of Page
   

- Advertisement -