帮忙写个触发器

来源:百度知道 编辑:UC知道 时间:2024/09/21 08:49:44
要求一个表中的某个数据记录不能被删除
帮忙看下这个对吗?我在分析器里执行不出来
看完就结帖

create trigger bb
on employee
for update
as
if exists (select count(*) from deleted where lastname = 'doe')
begin
print'不能删除'
end

create Trigger tb1_U On tb1 For Update

as
IF Exists
(Select * From deleted where col='已审核')
begin
RollBack Tran
Raiserror('已审核,本条记录不能被修改或删除',16,-1)
Return
end

或者:

rs.open "select * from table where 条件='' and fields='已审核'",cn,1,3
if rs.eof then
' 只有当列为未审核时再删除也很方便的
' update table set col1= where 条件
' delete from table where 条件
end if

如果按照你的想法,也最好是用存储过程来做

CREATE PRCO UP_test
@参数1 int,
@参数2 varchar(8)
as

if not exists(select * from talbe where COL=@参数1 and fields='已审核' )
---不存在时再 delete 或UPDATE ;<