I've decided to share my experience in trying to copy data from all tables into the same name tables in a different schema. I'm sure my experience can help others seeking mass table operations without using the unsupported and frankly limited sp_MSforeachtable
.
Objective: Copy data from all tables in my database to identically named tables with different schema
One quick note about sp_MSforeachtable
. Most of the time when people ask questions here in SO about this stored procedure, there's some reply or another saying that we shouldn't use unsupported features. This is simply not true, what we shouldn't do is have practices and design decisions based on unsupported features, mostly because they might go away.
But at some specific point in time, if an unsupported feature exists and does exactly what we need to do right then, one-off style, then just consider yourself lucky and by all means use it, just be careful about unexpected behaviors. When using such features, best to stick with simple operations whose output is quickly and easily verifiable.
With that said, and also because there's some real limitations to sp_MSforeachtable
, I am presenting a different but not too complicated way of executing statements against all (or specific) tables in our database and I'm using my problem as an example.