触发器如下:目的是禁止删除表中内容,级联字段一定要,不能去掉,有办法改进吗
CREATE TRIGGER candel来款
ON dbo.来款
instead of DELETE
AS
declare @bh as char(20)
if exists(select * from deleted where 来款 is not null or 客户id is not null)
begin
raiserror ('非法操作,请联系管理员!',16,1)
rollback tran
end
elsebegin
select @bh= 客户id from deleted
if exists(select * from 来款 where 客户id=@bh)
delete from 来款 where 客户id=@bh
end
CREATE TRIGGER candel来款
ON dbo.来款
instead of DELETE
AS
declare @bh as char(20)
if exists(select * from deleted where 来款 is not null or 客户id is not null)
begin
raiserror ('非法操作,请联系管理员!',16,1)
rollback tran
end
elsebegin
select @bh= 客户id from deleted
if exists(select * from 来款 where 客户id=@bh)
delete from 来款 where 客户id=@bh
end
解决方案 »
- 请教下一条update语句是怎么执行顺序的,有点不懂
- sql上 的 视图是怎么用的
- 急!全文检索问题!
- 如何连接两个不同地址不同类型数据库中的两个表
- 安装时的问题:在SQL Server 2000快安装完了时发生!!怎么没人能帮我么,好急哦!!
- и璶开数誹库让远祘ㄏノ蔍数誹库该ń设﹚㎡????
- 求sql算法: 不同数据库结构之间拷贝数据
- 急急急!!!!!!请问哪里有关于存储过程的细致讲解教程?????????????
- 累加语句中的判断
- 关于日期格式的转换
- 怎么循环插入一下数据>?
- 请大家进来看看,我这个怎么有错???
不然这样做,
例如做一个满足条件就删,不满足就不删...
如果还不可行的话,那么两个表的关联就自己做,使用触发器来进行