触发器问题,初学者请过多指教

python与大数据分析
博客专家认证
2003-02-23 01:46:57
/*
用途:保证在修改主代表时(即Other_Identity=‘1’)随从信息能够及时更新
*/
CREATE TRIGGER [TRIG_D_Forum_Representative_other] ON dbo.D_Forum_Representative
FOR INSERT, UPDATE
AS
Begin
IF UPDATE(Organization_Chi)
Update D_Forum_Representative Set
Organization_Chi = Organization_Chi
Where Main_Representative_ID=Representative_ID and other_identity<>'1'
意思当某一行Organization_Chi被修改时,
所有的Main_Representative_ID等于该修改行Representative_ID 值且other_identity<>'1'的Organization_Chi值都被修改为Organization_Chi

另外一个问题
删除是的触发器问题
当删除行other_identity = '1',则删除所有Main_Representative_ID=Representative_ID(该删除行值) 的值
when (other_identity = '1') then
delete from D_Forum_Representative
where Main_Representative_ID=Representative_ID
else when (other_identity <> '1')
update D_Forum_Representative
set
where Main_Representative_ID=Representative_ID and
(其它行值)Representative_ID <>Representative_ID (该行值)

...全文
28 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
caiyunxia 2003-02-23
  • 打赏
  • 举报
回复
up
pengdali 2003-02-23
  • 打赏
  • 举报
回复
create TRIGGER [TRIG_D_Forum_Representative_other] ON dbo.D_Forum_Representative
FOR UPDATE
AS
IF UPDATE(Organization_Chi)
Update D_Forum_Representative Set Organization_Chi=a.Organization_Chi from inserted a Where D_Forum_Representative.Main_Representative_ID=a.Representative_ID and D_Forum_Representative.other_identity<>'1'
fengzeng 2003-02-23
  • 打赏
  • 举报
回复
IF UPDATE(Organization_Chi)
Update D_Forum_Representative Set
Organization_Chi = a.Organization_Chi
from inserted a
Where D_Forum_Representative.Main_Representative_ID=a.Representative_ID and a.other_identity<>'1'
  • 打赏
  • 举报
回复
系统报告语法错误,Main_Representative_ID不明确
fengzeng 2003-02-23
  • 打赏
  • 举报
回复
IF UPDATE(Organization_Chi)
Update D_Forum_Representative Set
Organization_Chi = a.Organization_Chi
from inserted a
Where Main_Representative_ID=a.Representative_ID and a.other_identity<>'1'


delete from D_Forum_Representative
where Main_Representative_ID in(select Representative_ID from deleted where other_identity = '1')

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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