删除后触发更新另一个表

时间:2016-05-10 01:34:10

标签: sql-server triggers

SQL Server 2008:我尝试创建一个触发器,当Student中的列被删除时,该触发器会更改Enroll中列的值。

我一直在努力关注文档,但它已经超越了我的脑海。

谢谢。

CREATE TRIGGER Student_Drops
ON Enroll
AFTER DELETE
AS
    SET NOCOUNT ON;

    UPDATE Student
    SET Student.Credits = Student.Credits - 3
    WHERE Student.stuID = deleted.stuID

1 个答案:

答案 0 :(得分:0)

您的查询只适用于一行。可以同时删除多行吗?如果是这样,尝试这样的事情:

from django.contrib import messages
from django.shortcuts import redirect


def view1(request):
    if request.method == 'GET':
        initial_data = request.session.get('post_data', {})
        form = MyForm(initial=initial_data)
        ...


def view2(request):
    ...
    if error:
        request.session['post_data'] = request.POST
        messages.add_message(request, messages.ERROR, "Oops!")
        return redirect(request.META.get('HTTP_REFERER', '/'))