Based on the 2 databases below:
Database_A on Server_1
Database_B on Server_2
I have created a linked server to Database_B on Server_1 instance by name 'LS_B'.
I have a huge script file which basically creates required tables, functions, views, and stored procs on Database_A.
These functions, views and stored procs in turn refer to Database_B tables.
Problem is I have to now go and include OPENQUERY(LS_B,<query refering to database_b table>)
everywhere in the script file.
For instance
create procedure some_proc
as
begin
select * from openquery(LS_B, 'select * from [Database_B].[dbo].[Tabl开发者_Go百科e_1]');
end
Is there a better way to do this?
Pls. suggest.
Thanks
update
why does this fail
select top (50) * from LS_B.[Database_B].[dbo].[Table_1]
while the below works
select * from OpenQuery(LS_B, 'select top (50) * from Database_B.dbo.Table_1')
The error message on executing the first query is
Cannot process the object ""Database_B"."dbo"."Table_1"". The OLE DB provider "SQLNCLI10" for linked server "LS_B" indicates that either the object has no columns or the current user does not have permissions on that object
Both servers are on same domain.
If both servers are SQL servers you can use the following syntax:
select * from LS_B.[Database_B].[dbo].[Table_1]
It would depend on your exisitng syntax whether this would make it easier to do a find and replace.
You could also create a bunch of views on server 1 named after the tables refered to in the sps, then have these views refernce the linked server:
CREATE VIEW Table_1
AS
select * from LS_B.[Database_B].[dbo].[Table_1]
精彩评论