Points: 7084

8/3/2018 10:58:08 AM

Copy ANY TABLE from one database to another

* This article, and all our great SQL (General) documentation, Is available on the SQL (General) menu

Yesterday I was asked to move two tables from one database to another. Actually, it was to 'move the vendors from one database to the second database IF THEY DON'T EXIST'.

So, I wrote the code, and I blogged it. 'Cause that's what I do <smiles>

Today's request is to move 30 tables from one db to another, because of database corruption. Again, where the lines don't exist. 

So, I wrote a script that writes a script.

You enter in the from and to database, the table name, and the unique fields and it will write a script for you

You run it like this:

sp_MigrateTable '','fromdb', 'todb', 'SOP10100', 'docnumbr,rmdtypal'

You'll need several helper functions:

ddf_columnType: http://dyndeveloper.com/ArticleView.aspx?ArticleID=1707

DDReservedWords: http://dyndeveloper.com/ArticleView.aspx?ArticleID=2893 

ddv_DALTableColumnMetaData: http://dyndeveloper.com/ArticleView.aspx?ArticleID=2894  


Version: All
Section: SQL Scripts
Table Definition Quick Links
All Tables
SOP Tables
RM Tables
GL Tables
POP Tables
HR Tables
PM Tables
UPR Tables
IV Tables
Olympic Tables