用sql定义触发器 当删除采购表中的某一列数据时 对应在商品表的那一段数据就删除
展开全部
CREATE TRIGGER MyTri
ON dep /*触发器建立在表dep上*/
AFTER UPDATE/*触发器在表更新的时候触发*/
AS
BEGIN
declare @olddepid char(20)/*depid字段更新前的数据*/
declare @newdepid char(20)/*depid字段更新后的数据*/
select @oldsdepid=depid from deleted
select @newdepid=depid from inserted
update stu set depid=@newdepid where depid=@olddepid/*depid字段在dep中跟新后,在stu表中更新*/
END
GO
执行
update dep set depid='更改后值' where depid='更改前值'
ON dep /*触发器建立在表dep上*/
AFTER UPDATE/*触发器在表更新的时候触发*/
AS
BEGIN
declare @olddepid char(20)/*depid字段更新前的数据*/
declare @newdepid char(20)/*depid字段更新后的数据*/
select @oldsdepid=depid from deleted
select @newdepid=depid from inserted
update stu set depid=@newdepid where depid=@olddepid/*depid字段在dep中跟新后,在stu表中更新*/
END
GO
执行
update dep set depid='更改后值' where depid='更改前值'
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询