Friday, March 9, 2012

Question on load/replace" in SQL Server

I have to periodically overwrite selected tables in one environment (Prod) with the contents of the same named tables from another environment (Staging).

There are about 200 tables involved.

In SQL Server what would be the best way to do this and minimize logging?

Thanks in advance.
GerryI usually do this:

0. bcp out all data from source
1. disable FKs as appropriate in dest
2. truncate/delete from tables in dest
3. bcp in all data to dest
4. re-enable FKs in dest

You could probably also use DTS/SSIS for this, but I prefer bcp because I like the cmd line.

EDIT: one thing I forgot: step 2.1 should be to drop all indexes in dest, then at 4.1 recreate indexes. with indexes dropped the data will import much faster.

No comments:

Post a Comment