Tuesday, March 20, 2012

Could Stored Procedure or Trigger choose another database on difference engine?

Could Stored Procedure or Trigger
choose another database that is on difference engine? For example, I
have database A on engine or instance name Server1 that has a stored
procedure Stored_Proc_1 and in this stored procedure I want to access
some table on database B on engine Server2. I have username and
password on Server2.
I know that we can access different database on the same engine or
instance name, using to methods:
1. Using 3-part names ex: on the sp we say Select * from
myDb.dbo.myTable
2. Creating a string variable and build up the syntax that needed, ex:
Declare @.myQuery nvarchar(2000)
set @.myQuery = ' USE ' + @.dbname + CHAR(13) + 'SELECT * from
myTable'
Exec sp_executesql @.myQueryHi Lemune,
You can configure a linked server and then use 4 part name to access objects
on a different server.
Server_Name.DB_Name.Schema.Object
Note that there is a lot more overhead involved in this type of query
(distributed query) than accessing objects in DBs on the same server
instance.
Look in Books On Line for "Configuring linked servers"
HTH
Ami
"Lemune" <alfredosilitonga@.gmail.com> wrote in message
news:1148281973.632093.46050@.i39g2000cwa.googlegroups.com...
> Could Stored Procedure or Trigger
> choose another database that is on difference engine? For example, I
> have database A on engine or instance name Server1 that has a stored
> procedure Stored_Proc_1 and in this stored procedure I want to access
> some table on database B on engine Server2. I have username and
> password on Server2.
> I know that we can access different database on the same engine or
> instance name, using to methods:
> 1. Using 3-part names ex: on the sp we say Select * from
> myDb.dbo.myTable
> 2. Creating a string variable and build up the syntax that needed, ex:
> Declare @.myQuery nvarchar(2000)
> set @.myQuery = ' USE ' + @.dbname + CHAR(13) + 'SELECT * from
> myTable'
> Exec sp_executesql @.myQuery
>|||This problem occur because I develop a program for sms services. My
program use database to store incoming massage and out massage, If the
massage is having the right keyword it will do some task. And the task
is involved with another database. If according to myself I would
rather make my database on my client database (just adding my table to
my client database) or maybe adding my database to my client database
engine. But for some reason, my client refuses that method. So, I have
so make stored procedure on my program database engine that will
connect to my client database. I use this method so that I don't have
to change my program code each time my client use that rule :-).

No comments:

Post a Comment