Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 accessing global level

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2009-03-13 : 02:44:14
Hi,

I need to access objects(say like tables,procedures etc..) across Database within the server.For this i have create one test procedure under master database.but still iam not able to execute the procedure from different database.Could anyone correct me if
iam wrong?

shaggy
Posting Yak Master

248 Posts

Posted - 2009-03-13 : 02:54:40
could u post what u have done
Go to Top of Page

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2009-03-13 : 03:58:23
use Master
Go

Create Procedure Test
as
begin
set nocount on

select 'Hello' as output1

set nocount off
end

go

use Fin_Wh --Database
go

exec dbo.Test

Error thrown:
Msg 2812, Level 16, State 62, Line 1
Could not find stored procedure 'test'


quote:
Originally posted by shaggy

could u post what u have done

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-03-13 : 04:02:13
There is nothing like a "path" to access an object from whereever you want.
You need to access objects within one server via Databasename.Schemaname.Objectname.
Example select * from DB1.dbo.Table1

And don't spam the master database.

Greetings
Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2009-03-13 : 04:23:51
ok.please confirm whether only system related objects can be accessed across database.


quote:
Originally posted by webfred

There is nothing like a "path" to access an object from whereever you want.
You need to access objects within one server via Databasename.Schemaname.Objectname.
Example select * from DB1.dbo.Table1

And don't spam the master database.

Greetings
Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.

Go to Top of Page

shaggy
Posting Yak Master

248 Posts

Posted - 2009-03-13 : 04:48:57
use Master
Go

Create Procedure Test
as
begin
set nocount on

select 'Hello' as output1

set nocount off
end

go

use Fin_Wh --Database
go

exec master.dbo.Test



procedure with prefix as sp_ which is created on master can be accessed across server
Go to Top of Page
   

- Advertisement -