1

Within one database instance, I need to restore a set databases into new names. The new names will be suffixed based on the development phases, like: _DEV and _QA. Where:

  • DBApp_DEV shall access DBGen_DEV, and
  • DBApp_QA shall access DBGen_QA.

From DBApp_DEV, I would do this in an SP:

select Col1 from DBGen_DEV.dbo.TableName

However, from DBApp_QA I would have do this in the same SP:

select Col1 from DBGen_QA.dbo.TableName

Now, how can I synonymize the database name in that SP?

2
  • 1
    Why not use different server instances for development and QA? That way you wouldn't have this problem at all.
    – Andriy M
    Apr 14, 2016 at 9:16
  • There exists QA instance, but a bug needs to be resolved in Dev, hence the restore of QA into Dev without overwriting it. Apr 14, 2016 at 9:20

1 Answer 1

1

OK, I managed to solve this by creating a Synonym in DBApp_DEV:

CREATE SYNONYM GenTableName FOR DBGen_DEV.dbo.TableName

And in DBApp_QA, the Synonym would be:

CREATE SYNONYM GenTableName FOR DBGen_QA.dbo.TableName

This way, I can maintain the exact same query in my SP that exists in both DBApp_* databases:

select Col1 from GenTableName

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.