Search code examples
sql-serverssmsremote-accessremote-desktop

Query Run in different DB after returning to check remotely


Please help me on this.

I am running a query remotely on A.db, because it's a big data and maybe something is wrong on A.db that day so it took a long time. I don't spending time as long as I would get my result.

After hours of running(16 HOURS to be exact), the result is executing fail with some error. I went through the query and couldn't find any mistakes. But after a few read, I realize that the query has been executing in B.db instead of A.db that I was originally executing.

Is there any reason for the query to change to different db by itself? I read through the query and even let my colleague went through it, nothing is asking the query to run in different db.

Please help me on this, is has been bugged me for more than a week, I can't focus on others due to this problem.

Thank you


Solution

  • Hey this can't be run on different DB if you ran it on some DB. There might be chances that if you accidentally hit object explorer and selected different DB. enter image description here

    Better way you can do is just add

    Use DB_name
    

    at top of your query this will say engine to run query in that db which you said.

    Use a.DB
    SELECT distinct A.* from (