设为首页 加入收藏

TOP

sql 创建触发器
2011-06-12 21:38:42 来源: 作者: 【 】 浏览:438次 评论:0

sql 创建触发器

创建触发器语法

create trigger triggername on tablename
for insert |delete|update
as
begin

end

来面来看一下创建触发器的实例

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 


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

上面的功能是实例

要求是当我对ta1的tasl 修改时 触发,首先先比较ta1表中 tasl 是否 大于ta2表中 ta2ysh 如果大于ta2 表的 ta2ysh 则不允许进行修改操作,否则 先修改ta2表中的ta2sl 然后修改 ta1中的tasl

您看到此篇文章时的感受是:
Tags: 责任编辑:administrator
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到QQ空间
分享到: 
上一篇查询,删除,插入,查询,排序sql.. 下一篇mysql 数据库连接类

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

相关栏目

最新文章

图片主题

热门文章

推荐文章

相关文章

广告位