我有如下一个触发器,如何在查询分析器中执行这个触发器
USE [fysjj]
GO
/****** Object: Trigger [dbo].[tr_CQ_CheckCompany_delete] Script Date: 04/03/2015 22:49:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[tr_CQ_CheckCompany_delete]
ON [dbo].[CQ_CheckCompany]
AFTER delete
AS
BEGIN
declare
@id numeric(18)
declare myCursor cursor for
select @id from deleted
open myCursor
FETCH NEXT FROM myCursor into @id
while @@FETCH_STATUS = 0
begin
delete from CM_CONF_User where Company_ID = @id;
delete from CM_CONF_CompanyRole where Company_ID = @id;
delete from CM_CONF_Company where Company_ID = @id;
fetch next from myCursor into @id
end
close myCursor
deallocate myCursor
end
------解决思路----------------------
既然是触发器,就已经设定了条件的,应该按照这个条件来做就会运行触发器.
------解决思路----------------------
触发器不能显示执行
deleted表示在对表进行删除时才插入数据
你对触发器所在的表进行delete操作,触发器就自动触发
------解决思路----------------------
参照楼上,你只要对数据做删除操作 你的触发器将自动执行
你可以在查询分析器中执行 delete CQ_CheckCompany where Company_ID=***
------解决思路----------------------
用以下触发
Delete [dbo].[CQ_CheckCompany]
如果是测试,要加上事务如:
begin tran
Delete [dbo].[CQ_CheckCompany]
--看效果
select * from CM_CONF_User
select * from CM_CONF_CompanyRole
select * from CM_CONF_Company
rollback tran