Home > database >  When update A field in A table, table B content copied again change A field insert table B
When update A field in A table, table B content copied again change A field insert table B

Time:10-03

A table
A field two fields three
Q W 0
E R 0
Table B
Four field five field.
A C 0
G H 0
When the three fields in the table A update to 1, table of contents shows as follows:
A table
A field two fields three
Q W 1
E R 1
Table B
Four field five field.
A C 0
G H 0
A C 1
G H 1
Pray god help,

CodePudding user response:

 
SQL>
SQL> The create table a (c1 varchar (10), c2 varchar (10), the c3 int);
The Table created
SQL> The create table b (c1 varchar (10), c2 varchar (10), the c3 int);
The Table created
SQL> Create the trigger tri_a_up
2 before the update on a
3 for each row
4 the begin
Insert into 5 b values (: new c1, : new, c2, : new, c3);
6 the end;
7/
The Trigger created
SQL> Insert into a values (' a ', 'B', 0).
1 row inserted
SQL> Insert into a values (' C ', 'D', 0).
1 row inserted
SQL> Update a set c3=1;
2 rows updated
SQL> Select * from b;
C1 C2 C3
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
B, 1
C D 1
SQL> Drop table a purge;
Table dropped
SQL> Drop table b purge;
Table dropped

SQL>

CodePudding user response:

Pro, you the contents of this seems to be and I said a little discrepancy

CodePudding user response:

refer to the second floor qq_15637797 response:
, you the contents of this seems to be and I said a little discrepancy.


There must be some discrepancy, I just give you the sample code, specific business rules, you want your own organization;

CodePudding user response:

I mean you write this, the result is not I say like this, and I'm not a mean

CodePudding user response:

 
- to establish this trigger can meet the needs of you
The create or replace the trigger trig_T
Before the update on A table
For each row
The begin
If: New field three=1 then
Insert into table B
Select four fields, field 5, 1 from table B t where t. field six=0;
End the if;
end;

CodePudding user response:

 
- to establish this trigger can meet the needs of you
The create or replace the trigger trig_T
Before the update on A table
For each row
The begin
If: New field three=1 then
Insert into table B
Select four fields, field 5, 1 from table B t where t. field six=0;
End the if;
end;

CodePudding user response:

reference 4 floor qq_15637797 response:
I mean you write this, the result is not I say like this, and I'm not a mean


Say, the purpose of your update a row, write a few lines, update the two lines to write a few lines, besides these two tables have what relationship;

PS: others reply your post, if you still want to catch up with q, you'd better reference or @, so that the system will notify the other party;

CodePudding user response:

 
CREAT OR REPLACE the TRIGGER TRIG_I
BEFORE the UPDATE ON the table A
DECLARE IVSN NUMBER;
The BEGIN
SELECT DISTINCT fields INTO six IVSN FROM table B;
Three NOT. IF the NEW field IN IVSN THEN
INSERT INTO table B
SELECT four fields, field 5, MAX (field 6) + 1 AS field six
FROM table B
GROUP BY field four, five fields;
END the IF;
END;

So writing has a problem, could tell me where the problem is, beginners are too stupid,

CodePudding user response:

@ the net of selling fruits don't know how to use written language to describe, I feel so helpless
  • Related