MS SQL SERVER 2000,用trigger的我认为不能智能提醒,或者是我不会,麻烦详细点,谢谢。

解决方案 »

  1.   

    一个例子if exists(select 1 from sysobjects where name='tr_test' and xtype='TR')
    drop trigger dbo.tr_test
    go
    create trigger dbo.tr_test
    on table1
    instead of insert
    as
    declare @基本工资 int
    declare @福利奖金 int
    declare @失业保险 int
    select @基本工资=基本工资,@福利奖金=福利奖金,@失业保险=失业保险 from inserted
    if (@基本工资+@福利奖金-@失业保险)>3000
    begin
       print '错误:基本工资+福利奖金-失业保险 应该大于3000'
    end
    else
    begin
       insert into table1 select * from inserted
    end
    go至于具体的提示方式,可以通过mail,也可以自己另外写存储过程来做更详细明显的提示
      

  2.   

    我用了message提醒机制,但是不能非常显式的提示输入错误,虽然用户也不可能插入类似的数值。
    应用程序可以实现,但是如果直接跳过应用在数据库输入,就不好了,马其诺防线就破了。
      

  3.   

    如果写上RAISERROR(错误消息,错误号,错误级别,当前状态号)那么是以对话框的形式提醒用户回更加直观点。
    还可以使用SP_ADDMESSAGE将自己的错误消息添加到系同message中就更好用了,下次只要指定消息号码就ok了,谢谢宁哥,给分。