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 6786669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:16:24+00:00 2026-05-26T17:16:24+00:00

I struggled for a while with a bug, and then found out the reason

  • 0

I struggled for a while with a bug, and then found out the reason for it in a database stored procedure code, which contained the old name of a database in a table name, whereas the current database name was already different. So, I’d like to ask:

Is there a situation in which using a database name as a part of a full table name (database name + schema name + table name) can be justified (provided we don’t touch tables in other databases) or is it always a bad practice? How to correctly use a database name in sql scripts to keep code neutral to a specific database?

Code just for an illustration:

CREATE PROCEDURE [dbo].[MyProc] 
AS
BEGIN
 DELETE FROM [MyDatabase].[dbo].[MyTable] 
END
  • 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-26T17:16:25+00:00Added an answer on May 26, 2026 at 5:16 pm

    No, you shouldn’t use database names in a stored procedure unless you need to address two databases.

    It causes exactly the kinds of bugs you’re seeing. When the database name changes, all your SP code breaks, or continues working, but on the old database.

    It does make sense if you are sending a SQL query to the database, but only if the application dynamically picks the database name to insert into the query.

    My suggestion is that you do a full export of your database schema, and search for database names that are hardcoded and remove them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've always struggled with how to best include classes into my php code. Pathing
Have struggled with this call for a while now but i can't get it
I struggled finding a how-to which provides a stable solution for using Qt with
There's something I recurently struggle with while working on C++ code. Let's say I've
i struggled almost 1 hour but i couldn't figure it out as how to
Heres something I've been pondering for a while ... Do you struggle with the
I've struggled for the last couple of months to come up with some clean
I've struggled with this all day, I am trying to get a random number
Today I struggled with the following: $.ajax({url:'http://maps.google.com/maps/api/geocode/jsonaddress=Karachi&sensor=false&output=json&callback=?', dataType: 'json', success: function(data){ //eval((+data+)); alert(data); }
Here is a problem I've struggled with ever since I first started learning object-oriented

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.