Google+

Saturday, August 14, 2010

Creating a trigger based on two tables

SQL>
SQL>
SQL> CREATE TABLE myTable1 (a INTEGER, b CHAR(10));

Table created.

SQL>
SQL> CREATE TABLE myTable2 (c CHAR(10), d INTEGER);

Table created.

SQL>
SQL>
SQL> CREATE TRIGGER trig1
  2 AFTER INSERT ON myTable1
  3 REFERENCING NEW AS newRow
  4 FOR EACH ROW
  5 WHEN (newRow.a <= 10)
  6 BEGIN
  7 INSERT INTO myTable2 VALUES(:newRow.b, :newRow.a);
  8 END trig1;
  9

Trigger created.

SQL>
SQL> insert into myTable1 values(1,'a');

1 row created.

SQL> insert into myTable1 values(2,'b');

1 row created.

SQL>
SQL> select * from myTable1;

  A B
---------- ----------
  1 a
  2 b

SQL> select * from myTable2;

C D
---------- ----------
a 1
b 2

SQL>
SQL> drop table myTable1;

Table dropped.

SQL> drop table myTable2;

Table dropped.

Note:-Please comment and reply me.

0 comments:

Post a Comment