1、对远程表执行 UPDATE、 INSERT, 或 DELETET
update openquery(linked1, 'select ssn from testlinked where ssn=2')
set ssn=ssn + 1
insert openquery(linked1, 'select ssn from testlinked where 1=0') values (1000)
delete openquery(linked1, 'select ssn from testlinked where ssn>100')
2、使用 OpenQuery 动态执行
begin tran
SET QUOTED_IDENTIFIER OFF
SET XACT_ABORT ON
declare @cmd varchar(2500)
declare @cmd1 varchar(2500)
declare @var varchar(20)
set @var = 'White'
declare @var1 varchar(20)
set @var1 = 'White1'
declare @var2 varchar(20)
set @var2 = 'Johnson1'
select @cmd = "Update openquery(linked1,'select au_lname, au_fname from pubs.dbo.authors
where au_lname = ''" + @var + "''' )
set au_lname = '" + @var1 + "',
au_fname = '" + @var2 + "'"
exec ( @cmd )
commit tran
select * from <servername>.pubs.dbo.authors
posted on 2008-02-28 10:54
一凡 阅读(4399)
评论(0) 编辑 收藏 所属分类:
DATABASE