Sample Header Ad - 728x90

How to copy a database using scripts only, no bak, no mdf, no ldf

1 vote
1 answer
1055 views
Too often I face a terrible situation: I have a little time to take the backup of a customer db and download it for studying problems on it. The problem is that the database contains many BLOBs (as sql server filestream). Typically tabular data ("mdf") is 5% of the total data. To study most issues I do not need BLOBs. In a world with infinite bandwidth I could simply take a backup and download it, but this conflicts with "a little time" in the real world. To get rid of BLOBs I also do: 1. create a copy of the DB at the customer server 2. set all blobs to NULL 3. run CHECKPOINT to force filestream data clearing from disk 4. take backup after some time (proportional to BLOBs total size) 5. download a small backup BUT point (4) takes time. So what I would like to achieve is: a) create an empty database with a filestream filegroup on the customer's server b) with a script, create the schema (at least tables, views, sp, sf) on the copied DB c) with a script copy all the data but not the BLOBs d) take backup and download With my knowledge I can somehow manage (b) using the Tasks/Generate Scripts feature of Management Studio. Then manually I should write queries like this to fill the tables: INSERT INTO CopiedDB.dbo.Table1 SELECT * from MainDB.dbo.Table1 It is a very long procedure to be done manually even because the insert order must be sorted out manually (because of FK relationships). Is there a way to create this script in a smart way avoiding the manual way?
Asked by user193655 (145 rep)
Oct 26, 2017, 08:00 AM
Last activity: Nov 2, 2017, 10:18 AM