如何创建一个触发器

yibo2010 2010-07-23 03:02:07
create table ta1
(
taid int identity(1001,1) primary key ,
taName varchar(20) not null,
tasl int
)


create table ta2
(
ta2id int identity(1001,1) primary key ,
ta2Name varchar(20) not null,
ta2ysh int,
ta2sl int
)

要求是当我对ta1的tasl 修改时 触发,首先先比较ta1表中 tasl 是否 大于ta2表中 ta2ysh 如果大于ta2 表的 ta2ysh 则不允许进行修改操作,否则 先修改ta2表中的ta2sl 然后修改 ta1中的tasl。
...全文
85 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
永生天地 2010-07-23
  • 打赏
  • 举报
回复
也许
create trigger tru_ta1
on ta1
for update
as
begin
if exists(select 1 from ta2,inserted where ta2id=taid and ta2ysh < tasl)
rollback
else
update ta2 set ta2sl=tasl
from inserted where ta2id=taid
end
yibo2010 2010-07-23
  • 打赏
  • 举报
回复
基本的语句会 ,主要是参数怎么弄。 条件可以是taid=ta2id
csuxp2008 2010-07-23
  • 打赏
  • 举报
回复
两个表关联字段是什么?
cheng20100915 2010-07-23
  • 打赏
  • 举报
回复
.....帮你顶帖
bancxc 2010-07-23
  • 打赏
  • 举报
回复
create trigger triggername on tablename
for insert |delete|update
as
begin


end

22,300

社区成员

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

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