--2006-8-22
--msn: zhangchunwen@163.com
CREATE TRIGGER TRIGGER_INSERT on xfile
for INSERT
AS
BEGIN
declare @f_id int
select @f_id=f_id from inserted
INSERT INTO b.dbo.xfile(f_title,f_content,guid)
select a.f_title,b.f_content,a.guid
from inserted a,xfile b where a.f_id=b.f_id
END
--删除触发器--------------------------------------------------------------------------------
--2006-8-22
--msn: zhangchunwen@163.com
CREATE TRIGGER TRIGGER_delete on xfile
for delete
AS
IF @@RowCount = 0 Return
Declare @id varchar(50)
declare @sql varchar(500)
begin
Select @id = guid From deleted
set @sql='delete b.dbo.xfile where guid='''+@id+''''
print(@sql)
exec(@sql)
end
-------------------------------------------------------------------------------------------
--更新触发器--------------------------------------------------------------------------------
--2006-8-22
--msn: zhangchunwen@163.com
CREATE TRIGGER TRIGGER_update on xfile
for update
AS
IF @@RowCount = 0 Return
begin
update b.dbo.xfile
set f_title=b.f_title,f_content=a.f_content from xfile a,inserted b,b.dbo.xfile c
where a.f_id=b.f_id and b.guid=c.guid
END
---------------------------------------------------------------------------------------------
a,b 两个数据库 相同的表XFILE。
在A数据库的表XFILE上面执行触发器
解决问题:
1、在触发器内不能定义变量@f_content ,
2、在inserted,deleted 中不能使用 text,ntext,image问题.
如果有什么问题,请联系QQ:34028256 MSN:zhangchunwen@163.com