小新 的 BLOG
            
            -=Oracle、MS SQLServer还有MySQL,当然也少不了应用程序数据库操作=-

没有办法还得捡起SQLServer来用-触发器

------------------------------------------- 1 -------------------------------------------
USE qzeip_ec
DROP TRIGGER ent_user_update
GO
CREATE TRIGGER ent_user_update ON ec_ent_user
after update,insert
as
declare
@updatecount Int,
@sycount int,
@userid Char(36)
begin
  BEGIN Tran T1
  Set @userid = (select name from inserted)
  Set @updatecount = (Select count(*) From sy_user where sy_user.userid = @userid)
  if @updatecount > 0
    begin
    update sy_user set password = ins.password,username = ins.contman from inserted ins where sy_user.userid = ins.name    
    end
  else
    begin
    insert into sy_user(userid,password,username)SELECT ins.name,ins.password,ins.contman FROM inserted ins
    end
If @@Error = 0
begin
Set @updatecount = (Select count(*) From sy_user where sy_user.userid = @userid)
if @updatecount > 1
Begin
   Rollback Tran T1
Raiserror('该用户ID已经存在',16,1)
End
else
  begin
Commit Tran
  end
end
Else
Begin
  Rollback Tran T1
  Raiserror('修改失败',16,1)
End
  
  
end
GO
------------------------------------------- 2 -------------------------------------------
USE qzeip_ec
DROP TRIGGER ent_user_delete
GO
CREATE TRIGGER ent_user_delete ON ec_ent_user
after delete
as
begin
  delete from sy_user where userid in (select del.name from deleted del)
end
GO
标签集:TAGS:
回复Comments()点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}
  用户登录
用户名
密 码
选 项:
 
  我的日历
  分类日志
  访问计数
  获取 RSS
bluelover 最新的 20 条日志
  最新评论
  友情链接
  联系我
                  GMail:bluelover@gmail.com
MSN:xini_huang@hotmail.com
QQ:85364603
Modified by blueloverPowered by 5DBlog.com