Working around schema drift in SQL Server


 

At Stack Overflow, our environment has multiple implementations of a largely – but not 100% – identical schema. (By “schema,” I mostly mean the set of tables within a database.) I sometimes need to retrieve or update data across a large number of sites. Let’s say, pulling or removing information from the Users table, and related tables, across all of our databases.

This gets complicated.

Because:

Each of our Q & A sites has its own database, and each database has a table called Users (and some metadata is split out into a separate UserMetadata table). A few sites