locked
accessing another database on the same server RRS feed

  • Question

  •  

    Let's assume we have 2 databases db1 &  db2

    and we have a table named "MyTable" which is located in db2 database

    in the db1 database I create a stored procedure by using following code:

    <<

          use db1

          create procedure myproc

          as begin

           select * from db2.dbo.MyTable

         end;

    >>

    this code does not execute successfuly and I face an error which says << invalid object db2.dbo.MyTable>>

    and as you know we are not allowed to use USE database key word in stored procedures

    I can's access a table which is located in another database, whithin a stored procedure which is located in different data base but on the same server

    thanks

     

         

    Thursday, August 10, 2006 8:15 PM

Answers

  • i try simulating that problem

    it seems to work

    use northwind

          create procedure myproc


          as begin

           select * from pubs.dbo.authors

          end;

    can you please try this code alone

          use db1

          select * from db2.dbo.MyTable

    Thursday, August 10, 2006 9:14 PM