存储过程中更新另一台服务器上的表,可以码?

在数据库基础区看到这个帖子,
有没有人试过,我只有一台机子,所以。。。

主 题: 存储过程中更新另一台服务器上的表?
作 者: jaguar110 (美洲虎)
等 级:
信 誉 值: 100
所属论坛: 数据库基础
问题点数: 20
回复次数: 0
发表时间: 2002-09-03 16:22:41

两个数据库都是SQL SERVER
CREATE PROCEDURE wz_datapipes AS
begin
update wang.wzdb.wz_bm_gys
set gysno = t.gysno,
gysname = t.gysname,
gyslx = t.gyslx,
gysdh = t.gysdh,
gysdz = t.gysdz
from wz_bm_gys t
end
GO
我想更新wang这台机子上的wzdb中的表,但是执行过程中出错!说无效的表名“wang.wzdb.wz_bm_gys”清问各位高手为什么?我察看帮助说可以这样用,说“如果表或视图存在于本地服务器之外的一台链接的服务器上,应按以下格式使用由四部分组成的名称:linked_server.catalog.schema.object。”但我不知道怎么用?
---------------------------------------------------------------

wang.wzdb.wz_bm_gys

中间似乎少了一项

wang.wzdb.dbo.wz_bm_gys
---------------------------------------------------------------

search for "remote stored procedures" in Books Online:

How to set up a remote server to allow the use of remote stored procedures (Transact-SQL)

To set up a remote server to allow the use of remote stored procedures

Run the following code on the first server running Microsoft® SQL Server™:

EXEC sp_addlinkedserver ServerName1, N'SQL Server'
EXEC sp_addlinkedserver ServerName2
EXEC sp_configure 'remote access', 1
RECONFIGURE
GO

Stop and restart the first SQL Server.

Run the following code on the second SQL Server. Make sure you are logging in using SQL Server Authentication.
-- The example shows how to set up access for a login 'sa'
-- from ServerName1 on ServerName2.
EXEC sp_addlinkedserver ServerName2, local
EXEC sp_addlinkedserver ServerName1
EXEC sp_configure 'remote access', 1
RECONFIGURE
GO
-- Assumes that the login 'sa' in ServerName2 and ServerName1
-- have the same password.
EXEC sp_addremotelogin ServerName1, sa, sa
GO

Stop and restart the second SQL Server.

Using the sa login, you can now execute a stored procedure on the second SQL Server from the first SQL Server.

Published At
Categories with 数据库类
comments powered by Disqus