简体   繁体   中英

When value of a column changes in one table , a record should be inserted in other table in oracle DB

I want a SQL procedure / function to solve the below mentioned problem:

I have 2 tables - Table A and table B.

  • Table A has 3 columns - name, number and flag.
  • Table B has 2 columns - name and number.

When a value of flag column changes in table A, a record should be inserted in table B with the same values of name and number from table A.

How can I achieve this?

You can achieve this by using triggers.

Triggers are procedures that are stored in the database and are implicitly run, or fired, when something happens .

You can write triggers that fire whenever and INSERT, UPDATE, or DELETE operation is performed on a particular table or view.

General Syntax:

CREATE TRIGGER WRITE_TRIGGER_NAME_HERE
  BEFORE UPDATE ON TABLE_A
  FOR EACH ROW
BEGIN
  WRITE_INSERT_STATEMENT_HERE_FOR_TABLE_B
END;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM