如何在PL / SQL上插入触发器之前创建 [英] How to create before insert trigger on PL/SQL

查看:62
本文介绍了如何在PL / SQL上插入触发器之前创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有emp2表,我想在工资列上插入触发器之前应用,我需要另一个旧值的表。

i试图将这个代码作为一个错误来执行。帮助我解决这个问题..



我是什么尝试过:



创建触发器sal_tr

更新工资之前

on emp2

开始

插入emp_bkp(:old.ename,old.salary);

end;

解决方案
- >首先,SQL Server使用 Transact SQL [ ^ ]不 PL / SQL [ ^ ]。 PLAC用于ORACLE,IBM DB2等。

- > SQL Server没有BEFORE INSERT触发器,它有 INSTEAD OF INSERT [ ^ ]触发类似(但不相同)的目的。

- >触发器在TABLE / VIEW上定义,而不是在列上定义

- >令人惊讶的是,您的代码不包含BEFORE INSERT触发器,而是具有BEFORE UPDATE触发器。它们是不同的。



如果您在SQL Server中查找 INSTEAD OF UPDATE 触发器检查以下内容 -

INSTEAD OF UPDATE触发器 [ ^ ]

SQL Server:而不是更新触发器示例 [ ^ ]

触发后,取代触发器示例 [ ^ ]



如果你需要的话rement是不同的,请告诉我。



希望,它有帮助:)


这可以帮助你: https://www.techonthenet.com/oracle/triggers/before_insert.php

i have emp2 table, i wanted to apply before insert trigger on salary column and i need another table with old values.
i was trying to execute this code it troughs as an error..help me to solve this problem..

What I have tried:

create trigger sal_tr
before update of salary
on emp2
begin
insert into emp_bkp(:old.ename,old.salary);
end;

解决方案

--> First of all, SQL Server uses Transact SQL[^] not PL/SQL[^]. PL/SQL is used by ORACLE, IBM DB2 etc.
--> SQL Server doesn't have BEFORE INSERT trigger, it has INSTEAD OF INSERT[^] trigger for similar (but not same) purpose.
--> Triggers are defined on TABLE/VIEW not on column
--> Surprisingly, your code doesn't contain a BEFORE INSERT trigger, rather it has BEFORE UPDATE trigger. They are different.

If you are looking for INSTEAD OF UPDATE trigger in SQL Server check following-
INSTEAD OF UPDATE Triggers[^]
SQL Server: Instead Of Update Trigger Example[^]
After Trigger, Instead of Trigger Example[^]

If your requirement is something different, please let me know.

Hope, it helps :)


This may help you : https://www.techonthenet.com/oracle/triggers/before_insert.php


这篇关于如何在PL / SQL上插入触发器之前创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆