Oracle deleting tables - oracle

Is it possible to delete automatically records from parent table when I delete connected records in child table in Oracle 10g. I found that I can remove child records when I delete connected parent records using ON DELETE CASCADE, but can I do reverse action?

Can the child table contain several child objects per parent? If not, simply define the delete constraint the other way around

Related

Update on any child table's row is locking entire parent table in oracle

I have a parent table PT having below columns
PT_ID,
PT1_ID,
PT2_ID,
PT_COMMENT
Another child table CT is there having below columns
CT_ID,
PT_ID,
PT1_ID,
PT2_ID,
CT_COMMENT
There are rows in CT table where foreign key columns are having null values (means no value)
If we are updating the CT_COMMENT in CT table for more than 320 rows and at the same time in another seesion we are trying to update one parent table comment in PT_COMMENT column which is not happening until child records update is not getting completed.
Here same Parent table PT_ID row is not getting updated in child table CT, Though Parent Table is getting stuck.
Can anyone help me out to figure it out the reason for locking?
Thank in advance
The index was not appropriate, hence the parent table was getting locked.
After the recreation of an index, now it is working.

Deleting the record in child reference table dynamically before deleting the parent

I have a table with primary key which is being used as reference key in several, so i am trying to build a script wherein it will first delete all the records in child table and then the parent key dynamically.
Note :- If there is any constraint on child table being referenced by other tables that also we need to take care of.

Informatica: Delete rows from multiple tables sequentially. Then Insert

Consider the following scenario:
Main Control Table: 100 rows (Denormalized table with multiple processing ID's).
Set of 10 Parent Tables populated based on Control table.
Set of 10 Child Tables populated based on the Parent tables.
For daily processing:
We need to delete the data from Child tables first.
Parent Tables next.
Control table last.
Then insert data into Control table using multiple Insert Statements as it is denormalized.
Is this possible in one mapping?
One suggestion is to use SQL Transform and just execute the SQL's one after the other.
Is there an alternative way of Handling this?

Oracle Index - full table scan/lock

Found this here:
In general, consider creating an index on a column in any of the following situations:
A referential integrity constraint exists on the indexed column or
columns. The index is a means to avoid a full table lock that would
otherwise be required if you update the parent table primary key,
merge into the parent table, or delete from the parent table.
I don't understand why a full table lock would occurr in such situation. I would've thought that if I tried to delete/update the primary key in the parent table that a full table scan would be performed on the child table.
Where does the lock come from?
Have a look at this Tom Kyte blog entry. In it, he refers to the Oracle documentation, where this explanation is offered:
Prevents a full table lock on the child table. Instead, the database acquires a row lock on the index.
Removes the need for a full table scan of the child table. As an illustration, assume that a user removes the record for department 10 from the departments table. If employees.department_id is not indexed, then the database must scan employees to see if any employees exist in department 10.
In the first scenario, if the column is not indexed, the entire table must be locked because Oracle does not know which rows must be updated in the child table. With an index, Oracle can identify the rows in question and just lock them. Without the full table lock, it would be possible to modify the parent and have another session modify the child to something that violated the constraint.

Deleting many records with child tables

Situation:
Table TBL has ~10k entries for deletion,
Table TBL has 14 child tables with delete rule "no action",
I want to delete 10k entries and referenced entries in child tables.
Procedure:
Delete records in child tables,
Disable constraints (if constraints are not disabled deletion in next step takes forever),
Delete records in TBL table,
Enable constraints.
Is there more elegant way for doing this?
The problem is that third step takes too long because it is checking 14 big tables for existence of non existent records. My procedure has good execution time but I think that there is more elegant way.
It sounds like you need to index your foreign keys on your child tables. Every time you delete a parent record without an index on the child table it must do a full table scan of the child to check if the foreign key constraint was broken.
With the index, it is at worst case an index range scan.
Edit:
More info, and a script to determine if this is your problem can be found here.
http://asktom.oracle.com/tkyte/unindex/index.html

Resources