Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6972899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:02:03+00:00 2026-05-27T17:02:03+00:00

Okay. I have a database that has bunch of stored procedures and references another

  • 0

Okay. I have a database that has bunch of stored procedures and references another database like this:

select * from DatabaseName.dbo.tableName... or
Insert into DatabaseName.dbo.tableName....

So. It references it around 500-1000 times in stored procedures. Now, what happens is that I need to run these stored procedures from one database referencing another database, like this:

 select * from AnotherDatabaseName.dbo.tableName... or
 Insert into AnotherDatabaseName.dbo.tableName....

As far as I understand sql server 2008 r2 does not have anything new that could help it and I have to build dynamic queries every time with a parameter, right? If this is the case, is there any decent easy way to do it?
I need to change every stored procedure and add a parameter @DatabaseInstance. Also, I need to reconfigure all of the queries. sounds scary. Any automated tool or something to help with that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:02:04+00:00Added an answer on May 27, 2026 at 5:02 pm

    Using code you can create synonym for the database in your DB. I.e. I’m using this code in SP to insert into specified database based on parameter (region)

    IF  EXISTS (SELECT * FROM sys.synonyms WHERE name = N'TABLE_SYNONYM') DROP SYNONYM [dbo].[TABLE_SYNONYM]
    IF @region_id not in (2,3) CREATE SYNONYM [dbo].[TABLE_SYNONYM] FOR [DB_US].[dbo].[mytable]
    IF @region_id = 2 CREATE SYNONYM [dbo].[TABLE_SYNONYM] FOR [DB_EU].[dbo].[mytable]
    IF @region_id = 3 CREATE SYNONYM [dbo].[TABLE_SYNONYM] FOR [DB_Asia].[dbo].[mytable]
    
    insert into [dbo].[TABLE_SYNONYM] (...) select ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the database just like this ==== Invoices ==== id customer_id description ====
I have movie database that has these tables: new_movies, ratings, critic_ratings, colors I'm trying
Okay, so we have a utility here in-house that generates business-model classes from our
We have a database in production that already has a good number of rows
Okay so I made some changes to a stored procedure that we have, and
i have a datagrid that load the data from my database. in my datagrid,
Okay, so I have a database project for my database class. I have a
To anyone who can help, Thanks Okay, so I have a database holding a
okay i have been trying to understand this for hours i am learning VB
Okay I have a large CRUD app that uses tabs with Forms embedded in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.