创建一个delete触发器,如果有删除的员工是基本工资大于3000元并属于‘开发部’的则取消删除操作!
2个回答
展开全部
推荐使用instead of触发器(理由:没有必要插入后删除,浪费系统资源),代码如下:
create trigger Mytr
on 表名
instead of deleted
as
delete from 表名 from (
select * from deleted
where (deleted.部门='开发部' and deleted.工资<3000) or deleted.部门<>'开发部'
) as a
where a.员工编号=表名.员工编号
create trigger Mytr
on 表名
instead of deleted
as
delete from 表名 from (
select * from deleted
where (deleted.部门='开发部' and deleted.工资<3000) or deleted.部门<>'开发部'
) as a
where a.员工编号=表名.员工编号
展开全部
create TRIGGER [tg_PersonnelDelete]
ON [dbo].[PersonnelDate] --员工表
instead of DELETE
AS
BEGIN
declare @code varchar(50), @department varchar(50),@totalmoney money
select @code=code,@department=department,@totalmoney=totalmoney from deleted
--code为唯一标识的员工号,department为部门,totalmoney为金额
if @totalmoney>3000 and @department='开发部'
begin
select @code='员工:'+@code+'基本工资大于3000元并属于‘开发部’,不能进行删除!'
raiserror(@s,16,10)
end
else
begin
delete from PersonnelDate where code=@code
end
END
ON [dbo].[PersonnelDate] --员工表
instead of DELETE
AS
BEGIN
declare @code varchar(50), @department varchar(50),@totalmoney money
select @code=code,@department=department,@totalmoney=totalmoney from deleted
--code为唯一标识的员工号,department为部门,totalmoney为金额
if @totalmoney>3000 and @department='开发部'
begin
select @code='员工:'+@code+'基本工资大于3000元并属于‘开发部’,不能进行删除!'
raiserror(@s,16,10)
end
else
begin
delete from PersonnelDate where code=@code
end
END
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询