Sql-server – Make View Supersede Table in Same Database

sql-server-2008-r2view

For testing purposes we have a sanitized copy of our production database in our test world. Because of the way it is sanitized, we now have empty fields where encrypted data previously existed. We would like to be able to run against the database and have dummy data appear to be in the empty sanitized fields.

My initial thought is to have views with the same name as the sanitized tables that would return dummy (probably fixed) data in the empty fields. However, my understanding is that a View cannot exist with the same name as a Table. Is it possible to work around this?

My first thought was to use schemas, but I don't know enough about schemas at the moment. My second thought is to have a second "wrapper" database that references objects in the first database.

Is there a common practice for handling this sort of task?

Best Answer

You could use an updatable view as a proxy in front of the base table behind it. The view should behave the same way the table did, with some exceptions (for example, TRUNCATE will not work).

The table can the have any name because it is never referenced by app code.