--不能.要改为:
CREATE TRIGGER [equpdate] ON [dbo].[equipment]
FOR UPDATE
AS
declare @oldbh char(10),@newbh char(10)declare new cursor local for select num from inserted
declare old cursor local for select num from deletedopen new
open oldfetch next from new into @newbh
fetch next from old into @oldbh
while @@fetch_status=0
begin
update server_t set num=@newbh where @oldbh!=@newbh
fetch next from new into @newbh
fetch next from old into @oldbh
endclose old
close new
deallocate new
deallocate old
go
CREATE TRIGGER [equpdate] ON [dbo].[equipment]
FOR UPDATE
AS
declare @oldbh char(10),@newbh char(10)declare new cursor local for select num from inserted
declare old cursor local for select num from deletedopen new
open oldfetch next from new into @newbh
fetch next from old into @oldbh
while @@fetch_status=0
begin
update server_t set num=@newbh where @oldbh!=@newbh
fetch next from new into @newbh
fetch next from old into @oldbh
endclose old
close new
deallocate new
deallocate old
go
CREATE TRIGGER [equpdate] ON [dbo].[equipment]
FOR UPDATE
AS
declare @oldbh char(10),@newbh char(10)declare new cursor local for select num from inserted
declare old cursor local for select num from deletedopen new
open oldfetch next from new into @newbh
fetch next from old into @oldbh
while @@fetch_status=0
begin
if @oldbh<>@newbh update server_t set num=@newbh where num=@oldbh
fetch next from new into @newbh
fetch next from old into @oldbh
endclose old
close new
deallocate new
deallocate old
go
FOR UPDATE
AS
select id=identity(int,1,1),num into #t1 from inserted
select id=identity(int,1,1),num into #t2 from deletedupdate server_t set num=b.n_num
from server_t a join(
select n_num=a.num,o_num=b.num
from #t1 a join #t2 b on a.id=b.id
where a.num<>b.num) b on a.num=b.o_num
go
equipment.num是主关键字有唯一的值,
server_t.num不是关键字是有重复的值的。
它们是一对多的关系。
FOR UPDATE
AS
if (select count(*) from inserted)>1
rollback tranupdate server_t set num=(select num from inserted) where num=(select num from deleted)
go
alter table equipment add id int identity然后:
CREATE TRIGGER [equpdate] ON [dbo].[equipment]
FOR UPDATE
AS
update A set num=B.num from server_t A,inserted B,deleted C
where B.id=C.id and A.num=C.num and B.num<>C.num