这个触发器怎么创建

人在江湖漂那能不挨刀 2003-09-03 08:00:58
表1:
Goods(
[GoodsID] [char] (4) ,
[GoodsName] [varchar] (30) ,
[GdTID] [char] (1) ,
[UnitID] [char] (2) ,
[Flag] [char] (1)
)
表2:
GoodsType (
[GdTID] [char] (1) ,
[GdTName] [varchar] (20) ,
[Flag] [char] (1)
)
表3:
GoodsUnit(
[UnitID] [char] (2) ,
[UnitName] [varchar] (8) ,
[Flag] [char] (1)
)

表1
[GdTID] [char] (1) ,
[UnitID] [char] (2) ,
和表2:[GdTID] [char] (1) 表3:[UnitID] [char] (2) 关联
但表1:插入值时,表2,表3的[Flag] [char] (1) 相应的都变为'T'

例:在表1:插入:0001,笔,A,01,T
则:表2:GdtID=A 的记录的Flag字段要变为:'T'
表3:UnitID=A 的记录的Flag字段要变为:'T'
...全文
97 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 元老 2003-09-03
  • 打赏
  • 举报
回复
上面的按错键了

或:
create trigger t_insert on Goods
for insert
as
update GoodsType set flag='T' from GoodsType a where exists(select 1 from inserted where gdtid=a.gdtid)

update GoodsUnitset set flag='T' from GoodsUnitset a where exists(select 1 from inserted where gdtid=a.unitid )
go
zjcxc 元老 2003-09-03
  • 打赏
  • 举报
回复
create trigger t_insert on Goods
for insert
as
update GoodsType set flag='T' where gdtid in(select gdtid from inserted)
update GoodsUnitset flag='T' where unitid in(select gdtid from inserted)
go

或:
create trigger t_insert on Goods
for insert
as
update GoodsType set flag='T' where gdtid in(select gdtid from inserted)
update GoodsUnitset flag='T' where unitid in(select gdtid from inserted)
go

pengdali 2003-09-03
  • 打赏
  • 举报
回复
CREATE TRIGGER 名1 ON Goods
FOR INSERT
AS
update GoodsType set Flag='T' where GdTID in (select GdTID from inserted)
update GoodsUnit set Flag='T' where UnitID in (select UnitID from inserted)
go
txlicenhe 2003-09-03
  • 打赏
  • 举报
回复
Create Trigger yourTriggerName on Goods
For Insert
As
update GoodsType set Flag = 'T' where TdTID in (select GoodsID from inserted)
update GoodUnit set Flag = 'T' where UnitID in (select GoodsID From inserted)

34,874

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧