如何引用刚刚插入的值(在 TRIGGER 语句中)?
CREATE TRIGGER ATTENDANCE_INSERTION_TRIGGER
ON course_enrollment
AFTER INSERT
AS
BEGIN
--insert **what just was inserted in course_enrollment** into course_schedule_attendance
END
GO
如何引用刚刚在 course_enrollment 中插入的内容?
CREATE TRIGGER ATTENDANCE_INSERTION_TRIGGER
ON course_enrollment
AFTER INSERT
AS
BEGIN
--insert **what just was inserted in course_enrollment** into course_schedule_attendance
END
GO
How do I refer to what just was inserted in course_enrollment ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
您也可以在单个 INSERT 中执行此操作,无需触发器:
try this:
you could also do this in a single INSERT, without the trigger:
您可以从插入的表中获取值
因此,例如,如果 course_enrollment 有一个名为 course_id 和 Student_id 的字段,要获取这些字段,您可以执行以下操作
You can get the values from the inserted table
So for example if course_enrollment had a field called course_id and student_id, to get those fields you can do a
有两个有用的触发器元表,它们都与触发器所在的表的架构相匹配:INSERTED 和 DELETED。
有趣的是,如果您运行更新语句,触发器元表将在 INSERTED 和 DELETED 中都有行,DELETED 行对应于“更新之前”,而 INSERTED 对应于“更新后”。
这也使其对于审计目的很有用。
There are two useful trigger meta-tables, both of which match the schema of the table that the trigger is on, INSERTED and DELETED.
Interestingly if you run an update statement, the trigger meta tables will be have rows in both INSERTED and DELETED, the DELETED rows corresponding to "before the update" and INSERTED with "after the update".
This also makes it useful for audit purposes.