Home » SQL & PL/SQL » SQL & PL/SQL » Simultaneous update in child table
|
|
|
Re: Simultaneous update in child table [message #617822 is a reply to message #617812] |
Thu, 03 July 2014 15:11 |
|
many_yammy
Messages: 4 Registered: July 2014
|
Junior Member |
|
|
Ok the whole story as below:
I have three tables:
CITYOBJEC
CREATE TABLE "ANDREAS"."CITYOBJECT"
( "ID" NUMBER NOT NULL ENABLE,
"CREATION_DATE" DATE,
"LAST_MODIFICATION_DATE" DATE,
"UPDATING_PERSON" VARCHAR2(256 BYTE),
"REASON_FOR_UPDATE" VARCHAR2(4000 BYTE),
CONSTRAINT "CITYOBJECT_PK" PRIMARY KEY ("ID"));
CAFM_BUILDING
CREATE TABLE "ANDREAS"."CAFM_BUILDING"
( "ID" NUMBER NOT NULL ENABLE,
"BUILDING_ID" VARCHAR2(4000 BYTE),
"FK_CITYOBJECT_ID" NUMBER,
CONSTRAINT "CAFM_BUILDING_PK" PRIMARY KEY ("ID"),
CONSTRAINT "CAFM_BUILDING_CITYOBJECT_FK1" FOREIGN KEY ("FK_CITYOBJECT_ID")
REFERENCES "ANDREAS"."CITYOBJECT" ("ID") ENABLE);
CAFM_FACADE
CREATE TABLE "ANDREAS"."CAFM_FACADE"
( "ID" NUMBER NOT NULL ENABLE,
"FACADE_ID" VARCHAR2(4000 BYTE),
"FK_CAFM_BUILDING" NUMBER NOT NULL ENABLE,
"FK_CITYOBJECT_ID" NUMBER,
CONSTRAINT "CAFM_FACADE_PK" PRIMARY KEY ("ID"),
CONSTRAINT "CAFM_FACADE_CAFM_BUILDING_FK1" FOREIGN KEY ("FK_CAFM_BUILDING")
REFERENCES "ANDREAS"."CAFM_BUILDING" ("ID") ENABLE,
CONSTRAINT "CAFM_FACADE_CITYOBJECT_FK1" FOREIGN KEY ("FK_CITYOBJECT_ID")
REFERENCES "ANDREAS"."CITYOBJECT" ("ID") ENABLE
);
Each building has several facades. and In the "CITYOBJECT" table I have per each entry in either of "CAFM_BUILDIN" AND "CAFM_FACADE" 1 entry. It means If I have 2 building one with 3 and the other with 4 facades in general in the "CITYOBJECT" I have 9 rows(2+(3+4)).
Well. What I have now is a table in it I have "BUILDING_ID", "ID" and all information required for the table "CITYOBJECT". With help of this table I can insert data into the "CITYOBJECT" and the update "FK_CITYOBJECT_ID" in the table "CAFM_BUILDING".
When the table "CAFM_BUILDING" was updated, the column "FK_CIYTOBJECT_ID" in the table "CAFM_FACADE" will be updated. This has been done in the way that for all facades belong to a building, the "FK_CIYTOBJECT_ID" of the facades will be the same as its building's "FK_CIYTOBJECT_ID".
So now the tables I have in this level can be populated with this insert queries:
INSERT INTO CAFM_BUILDING (ID, BUILDING_ID, FK_CITYOBJECT_ID)
VALUES (1, 100.08, 1);
INSERT INTO CAFM_BUILDING (ID, BUILDING_ID, FK_CITYOBJECT_ID)
VALUES (2, 100.10, 2);
INSERT INTO CITYOBJECT (ID, UPDATING_PERSON )
VALUES (1, 'Many');
INSERT INTO CITYOBJECT (ID, UPDATING_PERSON )
VALUES (2, 'Many');
INSERT INTO CAFM_FACADE (ID, FACADE_ID, FK_CAFM_BUILDING)
VALUES (1, '100.08_nord', 1);
INSERT INTO CAFM_FACADE (ID, FACADE_ID, FK_CAFM_BUILDING)
VALUES (2, '100.08_west', 1);
INSERT INTO CAFM_FACADE (ID, FACADE_ID, FK_CAFM_BUILDING)
VALUES (3, '100.08_sued', 1);
INSERT INTO CAFM_FACADE (ID, FACADE_ID, FK_CAFM_BUILDING)
VALUES (4, '100.08_ost', 1);
INSERT INTO CAFM_FACADE (ID, FACADE_ID, FK_CAFM_BUILDING)
VALUES (5, '100.10_west', 2);
INSERT INTO CAFM_FACADE (ID, FACADE_ID, FK_CAFM_BUILDING)
VALUES (6, '100.10_sued', 2);
INSERT INTO CAFM_FACADE (ID, FACADE_ID, FK_CAFM_BUILDING)
VALUES (7, '100.10_ost', 2);
Now what I am thinking of is:
For each entry in the "CAFM_FACADE" take the corresponding row from "CITYOBJECT" (where its "ID" is the same as "FK_CITYBJECT_ID" in the "CAFM_FACADE"), Insert it to the "CITYOBJECT" with a new "ID" and after inserting this row update the corresponding row in the "CAFM_FACADE".
I think there should be a possibility like a for loop or something as it is possible in Java for example and I need to do such a thing with PL/SQL.
Looking forward to see your comments:).
Best regards,
Mandana
|
|
|
|
|
Re: Simultaneous update in child table [message #617834 is a reply to message #617812] |
Thu, 03 July 2014 17:13 |
|
many_yammy
Messages: 4 Registered: July 2014
|
Junior Member |
|
|
Ok the whole story as below:
I have three tables:
CITYOBJEC
CREATE TABLE "ANDREAS"."CITYOBJECT"
( "ID" NUMBER NOT NULL ENABLE,
"CREATION_DATE" DATE,
"LAST_MODIFICATION_DATE" DATE,
"UPDATING_PERSON" VARCHAR2(256 BYTE),
"REASON_FOR_UPDATE" VARCHAR2(4000 BYTE),
CONSTRAINT "CITYOBJECT_PK" PRIMARY KEY ("ID"));
CAFM_BUILDING
CREATE TABLE "ANDREAS"."CAFM_BUILDING"
( "ID" NUMBER NOT NULL ENABLE,
"BUILDING_ID" VARCHAR2(4000 BYTE),
"FK_CITYOBJECT_ID" NUMBER,
CONSTRAINT "CAFM_BUILDING_PK" PRIMARY KEY ("ID"),
CONSTRAINT "CAFM_BUILDING_CITYOBJECT_FK1" FOREIGN KEY ("FK_CITYOBJECT_ID")
REFERENCES "ANDREAS"."CITYOBJECT" ("ID") ENABLE);
CAFM_FACADECREATE TABLE "ANDREAS"."CAFM_FACADE"
( "ID" NUMBER NOT NULL ENABLE,
"FACADE_ID" VARCHAR2(4000 BYTE),
"FK_CAFM_BUILDING" NUMBER NOT NULL ENABLE,
"FK_CITYOBJECT_ID" NUMBER,
CONSTRAINT "CAFM_FACADE_PK" PRIMARY KEY ("ID"),
CONSTRAINT "CAFM_FACADE_CAFM_BUILDING_FK1" FOREIGN KEY ("FK_CAFM_BUILDING")
REFERENCES "ANDREAS"."CAFM_BUILDING" ("ID") ENABLE,
CONSTRAINT "CAFM_FACADE_CITYOBJECT_FK1" FOREIGN KEY ("FK_CITYOBJECT_ID")
REFERENCES "ANDREAS"."CITYOBJECT" ("ID") ENABLE
);
Each building has several facades. and In the "CITYOBJECT" table I have per each entry in either of "CAFM_BUILDIN" AND "CAFM_FACADE" 1 entry. It means If I have 2 building one with 3 and the other with 4 facades in general in the "CITYOBJECT" I have 9 rows(2+(3+4)).
Well. What I have now is a table in it I have "BUILDING_ID", "ID" and all information required for the table "CITYOBJECT". With help of this table I can insert data into the "CITYOBJECT" and the update "FK_CITYOBJECT_ID" in the table "CAFM_BUILDING".
When the table "CAFM_BUILDING" was updated, the column "FK_CIYTOBJECT_ID" in the table "CAFM_FACADE" will be updated. This has been done in the way that for all facades belong to a building, the "FK_CIYTOBJECT_ID" of the facades will be the same as its building's "FK_CIYTOBJECT_ID".
So now the tables I have in this level can be populated with this insert queries:
INSERT INTO CAFM_BUILDING (ID, BUILDING_ID, FK_CITYOBJECT_ID)
VALUES (1, 100.08, 1);
INSERT INTO CAFM_BUILDING (ID, BUILDING_ID, FK_CITYOBJECT_ID)
VALUES (2, 100.10, 2);
INSERT INTO CITYOBJECT (ID, UPDATING_PERSON )
VALUES (1, 'Many');
INSERT INTO CITYOBJECT (ID, UPDATING_PERSON )
VALUES (2, 'Many');
INSERT INTO CAFM_FACADE (ID, FACADE_ID, FK_CAFM_BUILDING)
VALUES (1, '100.08_nord', 1);
INSERT INTO CAFM_FACADE (ID, FACADE_ID, FK_CAFM_BUILDING)
VALUES (2, '100.08_west', 1);
INSERT INTO CAFM_FACADE (ID, FACADE_ID, FK_CAFM_BUILDING)
VALUES (3, '100.08_sued', 1);
INSERT INTO CAFM_FACADE (ID, FACADE_ID, FK_CAFM_BUILDING)
VALUES (4, '100.08_ost', 1);
INSERT INTO CAFM_FACADE (ID, FACADE_ID, FK_CAFM_BUILDING)
VALUES (5, '100.10_west', 2);
INSERT INTO CAFM_FACADE (ID, FACADE_ID, FK_CAFM_BUILDING)
VALUES (6, '100.10_sued', 2);
INSERT INTO CAFM_FACADE (ID, FACADE_ID, FK_CAFM_BUILDING)
VALUES (7, '100.10_ost', 2);
Now what I am thinking of is:
For each entry in the "CAFM_FACADE" take the corresponding row from "CITYOBJECT" (where its "ID" is the same as "FK_CITYBJECT_ID" in the "CAFM_FACADE"), Insert it to the "CITYOBJECT" with a new "ID" and after inserting this row update the corresponding row in the "CAFM_FACADE".
I think there should be a possibility like a for loop or something as it is possible in Java for example and I need to do such a thing with PL/SQL.
Looking forward to see your comments:).
Best regards,
Mandana
|
|
|
Re: Simultaneous update in child table [message #617850 is a reply to message #617831] |
Fri, 04 July 2014 01:22 |
John Watson
Messages: 8931 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
many_yammy wrote on Thu, 03 July 2014 22:23Hummmmm.... I haven't heard anything about deferrable before.I just googled it.But not yet completely got it. Could you explain a bit. How this works? I mean how the constraint will be updated after each insert?
I am not inserting manually. I am working with FME and insert per each row in "CAFM_FACADE" one into "CITYOBJECT".
What did you not understand about deferrable constraints? Have you read the description in the SQL Language Reference?
And please do not duplicate your posts. It annoy people and will discourage assistance.
|
|
|
Goto Forum:
Current Time: Wed Apr 24 08:48:44 CDT 2024
|