pp5-过程化SQL.pptVIP

  • 23
  • 0
  • 约6.25千字
  • 约 35页
  • 2018-07-10 发布于上海
  • 举报
3、触发器例子-Insert 设Employees(EmpID,Name,Salary,DepID),Dept(DepID,Name,EmpCount,SumSalary),在Employees表中插入一条记录时,需要同时更新Dept表中的EmpCount和SumSalary Create Trigger Update_Dept On Employees For Insert As Declare @sal Int Declare @deptID Int Select @sal=(select salary from inserted) Select @DeptID=(select DepID from inserted) -- 要根据它确定Dept表中需更新的行 Update Dept Set EmpCount=EmpCount+1,SumSalary= SumSalary+@sal Where DepID=@DeptID 3、触发器例子-Instead of Delete 设Employees(EmpID,Name,Salary,DepID),Dept(DepID,Name,EmpCount,SumSalary),删除Dept记录时,须首先删除Employees中关联的记录 Create Trigger Del_All On Dept Instead of Dele

文档评论(0)

1亿VIP精品文档

相关文档