使用instead of 触发器
CREATE TRIGGER texttype_update
ON texttype
instead of UPDATEAS
declare @texttype_id int
declare @texttype varchar(20)
begin
update 外表 set ……
update 主表 set ……
end
CREATE TRIGGER texttype_update
ON texttype
instead of UPDATEAS
declare @texttype_id int
declare @texttype varchar(20)
begin
update 外表 set ……
update 主表 set ……
end
修改主键时,还是出现:
---------------------------
SQL Server 企业管理器
---------------------------
其他用户已经修改了该表或视图的内容;您正在修改的数据库行在数据库中已不存在。数据库错误: '[Microsoft][ODBC SQL Server Driver][SQL Server]UPDATE 语句与 COLUMN FOREIGN KEY 约束 'FK_news_texttype' 冲突。该冲突发生于数据库 'building',表 'texttype', column 'texttype_id'。[Microsoft][ODBC SQL Server Driver][SQL Server]语句已终止。'
---------------------------
确定 帮助
---------------------------USE building
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'texttype_update' AND type = 'TR')
DROP TRIGGER texttype_update
GOCREATE TRIGGER texttype_update
ON texttype
instead of UPDATEAS
declare @texttype_parent int
declare @texttype_id int
declare @texttype_id_s int
declare @texttype varchar(20)
declare @B_img1 nvarchar(255)
declare @B_img2 nvarchar(255)
IF (COLUMNS_UPDATED() & 6) > 0
begin
select @texttype_parent=texttype_parent,@texttype_id=texttype_id,@texttype=texttype,@B_img1=B_img1,@B_img2=B_img2 from Inserted
select @texttype_id_s=texttype_id from Deleted
update news set newstype_id=@texttype_id, newstype=@texttype where newstype_id=@texttype_id_s
update texttype set texttype_parent=@texttype_parent, texttype_id=@texttype_id, texttype=@texttype, B_img1=@B_img1, B_img2=@B_img2 where texttype_id=@texttype_id_s
end
GO