两个表 触发器 冲突
两个表之间互相插入与删除记录
我把触发器记录一下,哈哈。首次学,首次写。
对[dbo].[DNN_Roles]表的插入与删除之后进行操作:
create TRIGGER Trigger_DNN_UNIRMS_ADDROLES
ON [dbo].[DNN_Roles]
for INSERT
AS
BEGIN
declare @RoleName as VARCHAR(256)
select @RoleName=RoleName from INSERTED
exec [dbo].[aspnet_Roles_CreateRole] "DotNetNuke",@RoleName
END
create TRIGGER [dbo].[Trigger_DNN_UNIRMS_DELETEROLES]
ON [dbo].[DNN_Roles]
for delete
AS
BEGIN
declare @RoleName as VARCHAR(256)
select @RoleName=RoleName from deleted
exec [dbo].[aspnet_Roles_DeleteRole] "DotNetNuke",@RoleName,1
END
对[dbo].[aspnet_Roles]表的插入与删除之后进行操作:
create TRIGGER Trigger_UNIRMS_DNN_ADDROLES
ON [dbo].[aspnet_Roles]
for insert
AS
BEGIN
declare @RoleName2 as nvarchar(256)
select @RoleName2=RoleName from inserted
exec dbo.DNN_AddRole 0,NULL,@RoleName2,'','$0.0000',1,'N','$0.0000',1,'N',0,0,'',''
END
create TRIGGER [dbo].[Trigger_UNIRMS_DNN_DELETEROLES]
ON [dbo].[aspnet_Roles]
for delete
AS
BEGIN
declare @RoleId as int
declare @RoleName as VARCHAR(256)
select @RoleName=RoleName from deleted
select @RoleId=RoleId from DNN_Roles where RoleName=@RoleName
exec [dbo].[DNN_DeleteRole] @RoleId
END
执行后会出现冲突问题,也就是递归的问题。
我把数据库的服务器设置一下就好了。
右击服务器属性->高级->杂项(右边窗口)->允许触发器激发其他触发器 设置成False
我把触发器记录一下,哈哈。首次学,首次写。
对[dbo].[DNN_Roles]表的插入与删除之后进行操作:
create TRIGGER Trigger_DNN_UNIRMS_ADDROLES
ON [dbo].[DNN_Roles]
for INSERT
AS
BEGIN
declare @RoleName as VARCHAR(256)
select @RoleName=RoleName from INSERTED
exec [dbo].[aspnet_Roles_CreateRole] "DotNetNuke",@RoleName
END
create TRIGGER [dbo].[Trigger_DNN_UNIRMS_DELETEROLES]
ON [dbo].[DNN_Roles]
for delete
AS
BEGIN
declare @RoleName as VARCHAR(256)
select @RoleName=RoleName from deleted
exec [dbo].[aspnet_Roles_DeleteRole] "DotNetNuke",@RoleName,1
END
对[dbo].[aspnet_Roles]表的插入与删除之后进行操作:
create TRIGGER Trigger_UNIRMS_DNN_ADDROLES
ON [dbo].[aspnet_Roles]
for insert
AS
BEGIN
declare @RoleName2 as nvarchar(256)
select @RoleName2=RoleName from inserted
exec dbo.DNN_AddRole 0,NULL,@RoleName2,'','$0.0000',1,'N','$0.0000',1,'N',0,0,'',''
END
create TRIGGER [dbo].[Trigger_UNIRMS_DNN_DELETEROLES]
ON [dbo].[aspnet_Roles]
for delete
AS
BEGIN
declare @RoleId as int
declare @RoleName as VARCHAR(256)
select @RoleName=RoleName from deleted
select @RoleId=RoleId from DNN_Roles where RoleName=@RoleName
exec [dbo].[DNN_DeleteRole] @RoleId
END
执行后会出现冲突问题,也就是递归的问题。
我把数据库的服务器设置一下就好了。
右击服务器属性->高级->杂项(右边窗口)->允许触发器激发其他触发器 设置成False