Modify constraint for "on delete cascade"
hello all,
i have a table with a foriegn key to another table. this constraint define no action on delete on create time. but i want to modify this constraint for "on delete cascade" now. i entered following sql but get an error. how can help me?
SQL> alter table TBL1 modify(constraint TBL1_FK foreign key(GET_NO)
references TBL2 on delete cascade);
alter table TBL1 modify(constraint TBL1_FK foreign key(GET_NO)
references TBL2 on delete cascade);
ERROR at line 1:
ORA-02275: such a referential constraint already exists in the table
You can only modify a state of constraint. To change the action you have to drop and recreate it.
Best regards
Maxim
Similar Messages
-
How to alter the constraint for on delete cascade
Hi Guys,
I have a table which has 5 level of child tables .But all the child tables have the foreign keys without on delete cascade.But I have to delete a data in the parent table .One method I thought to change the child table constraints to ON DELETE CASCADE then delete the record and after that again to change the constraints with out the ON DELETE CASCADE.Please let me know wheather these is possible or not .If not is there any other alternatives to achive this.
Any suggestions would be highly appreciated.
Thanks in advance
PrafullaI think you need to drop and recreate your FKs.
See my example here.
create table TEST1
id NUMBER(12) not null,
anything VARCHAR2(20)
alter table TEST1
add constraint PK_TEST1 primary key (ID);
create table TEST2
id2 NUMBER(12) not null,
fk1 NUMBER(12),
info VARCHAR2(50)
alter table TEST2
add constraint PK_TEST2 primary key (ID2);
alter table TEST2
add constraint FK_TEST2_TO_TEST1 foreign key (FK1)
references TEST1 (ID);
-- and here is the code when I add on delete cascade for FK
alter table TEST2
drop constraint FK_TEST2_TO_TEST1;
alter table TEST2
add constraint FK_TEST2_TO_TEST1 foreign key (FK1)
references TEST1 (ID) on delete cascade; -
hi every body.
i want to add the constraint "ON DELETE CASCADE" on foreign key value in child table like.
ALTER table employee
Add CONSTRAINT cscade_dept_no ON DELETE CASCADE (Deptno)
but it display error message, so please help me in this regards.
Thanks
Edited by: BilalKhan on Feb 7, 2011 11:53 PMUsually, will be usefull look the error displayed.
Example:
ALTER table employee Add CONSTRAINT cscade_dept_no ON DELETE CASCADE (Deptno);
Error SQL: ORA-00904: :
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:Then we can say to you... Your syntaxis is wrong, you must use
ALTER TABLE table_name
add CONSTRAINT constraint_name
FOREIGN KEY (column1, column2, ... column_n)
REFERENCES parent_table (column1, column2, ... column_n)
ON DELETE CASCADE;
example
ALTER TABLE employee
add CONSTRAINT cscade_dept_no
FOREIGN KEY (Deptno)
REFERENCES Department (Deptno)
ON DELETE CASCADE; -
JPA - How can i add ON DELETE CASCADE constraint ?
I have a three tables.
1. A (name)
2. B (name)
and relationship(manytomany) table of A and B
3. C (a_name,b_name)
I am using 2 JPA entities@Entity
public class A {
@id
String name;
@ManyToMany
@JoinTable(name="C",
joinColumns=@JoinColumn(name="a_name"),
inverseJoinColumns=@JoinColumn(name="b_name"))
private List<B> bs = new ArrayList<B>();
//getter setter methos
}and@Entity
public class B {
@id
String name;
@ManyToMany(mappedBy="bs")
private List<A> as = new ArrayList<A>();
//getter setter methos
}DDL of table C which is generated by JPA is something like thatCREATE TABLE C (
"a_name" VARCHAR,
"b_name" VARCHAR,
CONSTRAINT "c_a_name_fkey" FOREIGN KEY ("a_name")
REFERENCES a(name)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT "c_b_name_fkey" FOREIGN KEY ("b_name")
REFERENCES b(name)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)but i want to add constraint ON DELETE CASCADE* instead of ON DELETE NO ACTION_ in above relationship table C.
how can i do this ?
Thanks in advance.Right click the message and select Edit as New.
-
How to temporarily disable on delete cascade but not the constraint
Hi all
i would like to know if this is possible
how to temporarily disable on delete cascade but not the constraint
i want to delete a row from the primary key table but i dont want the data from the foreign key to be deleted even though there is an on delete cascade set.
how do i temporarily disable on delete cascade from firing without disabling the constraint
RgrdsThere is an option which I've never used before but just read about which is to create your foreign key constraint as on delete SET NULL
instead of on delete cascade.
This will allow you to delete a parent and will set the foreign key column values in the child table to nulls
e.g.
SQL> create table parent (father varchar2(30) primary key,
2 age number);
Table created.
SQL>
SQL> create table child (father varchar2(30) constraint fk references parent(father) on delete set null,
2 child varchar2(30),
3 age number);
Table created.
SQL>
SQL> insert into parent values ('JOHN', 34);
1 row created.
SQL> insert into child values ('JOHN', 'SARAH', 10);
1 row created.
SQL> insert into child values ('JOHN', 'BILL', 12);
1 row created.
SQL>
SQL> commit;
Commit complete.
SQL>
SQL> delete from parent where father = 'JOHN';
1 row deleted.
SQL>
SQL> select * from child;
FATHER CHILD AGE
SARAH 10
BILL 12
SQL> HTH AMM -
Scripts for adding/deleting/modifying Open Directory accounts?
I think I have searched high and low for an answer to this question, but if I missed it please point me in the right direction. Where can I find information on scripts for adding/deleting/modifying open directory accounts? At the very least, a command line utility with some syntax guidelines! Any help would be greatly appreciated.
Hi
I personally don't know if any scripts although you can use the command line to do pretty much anything you want with the Open Directory. Consult the manual: man dscl. If you launch terminal and issue dscl you should see something like this:
my-Laptop:~ me$ dscl
dscl (v20.4)
usage: dscl [options] [<datasource> [<command>]]
datasource:
localhost (default) or
<hostname> (requires DS proxy support, >= DS-158) or
<nodename> (Directory Service style node name) or
<domainname> (NetInfo style domain name)
options:
-u <user> authenticate as user (required when using DS Proxy)
-P <password> authentication password
-p prompt for password
-raw don't strip off prefix from DS constants
-url print record attribute values in URL-style encoding
-q quiet - no interactive prompt
commands:
-read <path> [<key>...]
-create <record path> [<key> [<val>...]]
-delete <path> [<key> [<val>...]]
-list <path> [<key>]
-append <record path> <key> <val>...
-merge <record path> <key> <val>...
-change <record path> <key> <old value> <new value>
-changei <record path> <key> <value index> <new value>
-search <path> <key> <val>
-auth [<user> [<password>]]
-authonly [<user> [<password>]]
-passwd <user path> [<new password> | <old password> <new password>]
Entering interactive mode...
The above is for 10.4 and should server equally as well for 10.5.
Hope this helps, Tony -
How do I delete cascade with a PL/SQL procedure?
This script will create a PL/SQL procedure that deletes cascade. This is a post to contribute to the Oracle community. Take the code as is and test it before you use it in production. Make sure this is what you want.
Procedure Delete Cascade (prc_delete_cascade)
Description
=============
The principle is very simple. The procedure uses a table called TO_BE_DELETED to keep a list of records to be deleted. This
table keeps the table name and the rowid of those records that need to be deleted. The procedure also uses a function called
DELETE_BOTT_ROW which takes one record of the table and tries to delete it. If the deletion fails with a foreign key constraint
violation, the function parses the SQL error message (SQLERRM) to get the name of the constraint. With the name of the constraint,
the function finds the name of the child table, all the child records that have references to the parent table primary or unique key,
and the parent key primary or unique key column name. Once the child records of the failed delete are identified, the function takes their table name and rowids
and records them into the TO_BE_DELETED table by inserting records of their table name and their rowids. Al the records inserted also contain the level (which
is 1 for the original records, 2 for child records, 3 for granchild records, etc.) and the sequence number of the order in wich they
are recorded. This way, when the function picks up a record to be deleted, it takes the one with the highest level and the highest
inserted sequence, or the "bottom" record. Once all the child records of the failed delete are appended to the TO_BE_DELETED table, it calls itself
recursevely, and the function takes the record at the "bottom" of the table and tries to delete it. If it succeeds, it calls
itself recursevely to delete the next record. If it fails, it goes and finds the child records as described before and once they are
inserted into the TO_BE_DELETED table, it calls itself again recursevely to try to delete again the "bottom" record. All records
that are successfully deleted are flagged as deleted usig the flag_del column so they are not pickt up again. Once all the (parent,
child, grandchild, etc.) records are deleted, the procedure ends without commiting, giving the option to the user to commit or
rollback deletions. The table TO_BE_DELETED is, at the end of the procedure, a list of all the records that were deleted, including their table names
and the order in with they were deleted. The user then can review its content and decide to commit or rollback.
Restrictions
============
1. Single tables only. The procedure only takes one table name and a WHERE clause to identified the records to be deleted.
2. Single columns only. Ther procedure only works with single-column primary, unique and foreign key constraints.
3. Single schema only.
4. Unpredictable results with circular references.
drop table to_be_deleted purge;
create table to_be_deleted
(tname varchar2(30) -- table name
,rid rowid -- rowid
,lvl number -- level: 1=parent, 2=child, 3=grandchild, etc.
,seq_ins number -- sequence order of record inserted
,flg_del char -- flag deleted: Y=record deleted
,seq_del number -- global order of record deletion
set serveroutput on size 1000000
create or replace procedure prc_delete_cascade
(p_tname varchar2 -- table name
,p_where varchar2 -- where clause identifying records to be cascade deleted
is
dummy char;
v_sqlcode number;
v_sqlerrm varchar2(32767);
v_param_val integer := 0;
v_sql varchar2(4000);
v_ret_cde number;
e_bad_params exception;
v_iter number;
v_plvl number;
v_seq_del number;
v_max_iter number := 1000000000;
function delete_bott_row
return number
is
v_sql varchar2(4000);
v_ptname varchar2(30); -- parent table name
v_ppkname varchar2(30); -- parent primary key constraint name
v_ppkcname varchar2(30); -- parnet primary key column name
v_prowid rowid;
v_crowid rowid;
v_ctname varchar2(30); -- child table name
v_cfkname varchar2(30); -- child foreign key constraint name
v_cfkcname varchar2(30); -- child foreign key column name
v_ins number;
v_seq_ins number;
v_sqlerrm varchar2(4000);
v_sqlcode number;
e_const_viol exception;
pragma exception_init(e_const_viol, -2292);
e_max_iter_reached exception;
begin
v_iter := v_iter + 1;
if v_iter >= v_max_iter then
raise e_max_iter_reached;
end if;
dbms_output.put_line('- Iter '||to_char(v_iter));
dbms_output.put_line('----------');
dbms_output.put_line('- Starting function delete_bott_row');
v_sql := 'select tname, rid, lvl, seq_ins from (select * from to_be_deleted where flg_del = ''N'' order by lvl desc, seq_ins desc) where rownum=1';
-- dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql into v_ptname, v_prowid, v_plvl, v_seq_ins;
dbms_output.put_line('- Selected row: table name: '||v_ptname||', level: '||v_plvl||', seq: '||v_seq_ins);
v_sql := 'delete from '||v_ptname||' where rowid='''||v_prowid||'''';
dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql;
dbms_output.put_line('- Row deleted !!!');
v_ret_cde := 1;
v_seq_del := v_seq_del + 1;
dbms_output.put_line('- Mark the row deleted');
v_sql := 'update to_be_deleted set flg_del = ''Y'', seq_del = '||to_char(v_seq_del)||' where tname='''||v_ptname||''' and rid='''||v_prowid||'''';
-- dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql;
-- dbms_output.put_line('- Updated table to_be_deleted, row marked deleted');
-- dbms_output.put_line('- End of iter '||to_char(v_iter));
dbms_output.put_line('----------');
-- call function delete_bott_row recursively
v_ret_cde := delete_bott_row;
return 0;
exception
when no_data_found then
dbms_output.put_line('- Table to_be_deleted is empty, delete cascade has completed successfully.');
v_ret_cde := 0;
return 0;
when e_const_viol then
v_sqlcode := SQLCODE;
v_sqlerrm := SQLERRM;
v_ret_cde := v_sqlcode;
dbms_output.put_line('>Constraint Violation. Record has children');
-- dbms_output.put_line('Error code: '||to_char(v_sqlcode));
v_cfkname := substr(v_sqlerrm,instr(v_sqlerrm,'.')+1,instr(v_sqlerrm,')') - instr(v_sqlerrm,'.')-1);
dbms_output.put_line('>Child FK name: '||v_cfkname);
select table_name, column_name
into v_ctname, v_cfkcname
from user_cons_columns
where constraint_name=v_cfkname;
dbms_output.put_line('>Child table name: '||v_ctname||'. FK column name: '|| v_cfkcname);
select constraint_name, column_name
into v_ppkname, v_ppkcname
from user_cons_columns
where constraint_name = (select r_constraint_name
from user_constraints
where constraint_name=v_cfkname);
dbms_output.put_line('>Parent PK/UK name: '||v_ppkname||'. Parent PK/UK column: '||v_ppkcname);
v_sql := 'insert into to_be_deleted(tname, rid, lvl, seq_ins, flg_del) '||
'select '''||v_ctname||''', rowid, '||to_char(v_plvl+1)||', rownum, ''N'' '||
'from '||v_ctname||' '||
'where '||v_cfkcname||' =any (select '||v_ppkcname||' from '||v_ptname||' where rowid =any (select rid from to_be_deleted where tname = '''||v_ptname||'''))';
-- dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql;
select count(*)
into v_ins
from to_be_deleted
where lvl = v_plvl+1
and tname = v_ctname
and flg_del = 'N';
dbms_output.put_line('>Found '||to_char(v_ins)||' child records which were added to table to_be_deleted');
v_ret_cde := delete_bott_row;
return v_ret_cde;
when e_max_iter_reached then
dbms_output.put_line('Maximum iterations reached. Terminating procedure.');
raise;
when others then
raise;
end delete_bott_row;
begin
dbms_output.put_line('Beginning');
dbms_output.put_line('================================');
-- validate p_table
begin
select 'Y'
into dummy
from user_tables
where table_name=upper(p_tname);
exception
when no_data_found then
v_param_val := 1;
dbms_output.put_line('Table '||p_tname||' does not exist.');
raise e_bad_params;
end;
dbms_output.put_line('- Parameter p_tname validated');
-- validate p_where
begin
execute immediate 'select ''Y'' from '||p_tname||' where '||p_where INTO dummy;
exception
when no_data_found then -- where clause returns no records
dbms_output.put_line('Record(s) not found. Check your where clause parameter');
v_param_val := 2;
raise e_bad_params;
when too_many_rows then -- found multiple records means it is ok
null;
when others then -- any other records means where clause has something wrong.
dbms_output.put_line('Where clause is malformed');
v_param_val := 2;
raise e_bad_params;
end;
dbms_output.put_line('- Parameter p_where validated');
if v_param_val > 0 then raise e_bad_params; end if;
v_iter := 0;
v_plvl := 1;
v_seq_del := 0;
v_sql := 'insert into to_be_deleted(tname, rid, lvl, seq_ins, flg_del) select '''||upper(p_tname)||''', rowid, '||to_char(v_plvl)||', rownum, ''N'' from '||p_tname||' where '||p_where;
dbms_output.put_line('- Inserting initial record');
dbms_output.put_line('- SQL: '||v_sql);
execute immediate v_sql;
dbms_output.put_line('- Record(s) inserted');
dbms_output.put_line('- Calling function delete_bott_row to delete last row of table to_be_deleted');
dbms_output.put_line('-----------------------------------');
v_ret_cde := delete_bott_row;
-- dbms_output.put_line('- Back from function delete_bott_row');
-- dbms_output.put_line('Return code: '||to_char(v_ret_cde));
dbms_output.put_line('- End of procedure');
exception
when e_bad_params then
dbms_output.put_line('Bad parameters, exiting.');
end;
show errors
spool prc_delete_cascade.log
-- Call to the procedure
exec prc_delete_cascade('xent','xent_id between 1669 and 1670')
select tname "Table Name", count(*) "Rows deleted"
from to_be_deleted
group by tname;
spool off
set lines 120
select *
from to_be_deleted
order by seq_del;
prompt Now commit or rollaback deletions.
-- commit;
-- rollback;Edited by: Rodolfo4 on Mar 23, 2011 10:45 AMInteresting.
I see a few areas where this could be useful. Elimiating specific test records from a Test DB for example.
Some comments:
<li>Since this is a recursive logic you must add a stop criteria. In this case I would add a max iteration variable. If that one is reached, raise an error message and let the procedure stop with that error.</li>
<li>The when others exception at the end should be removed completely</li>
<li>The when others exception in the middle should be replaced by a specific exception that handles the -2292 error</li>
<li>A list of tables where no record should be deleted could be usefull. If the logic would encounter such a table, it should also stop. This would be to prevent that data from some system critical tables could be deleted per accident.</li>
<li>The reference from the FK constraint to the PK constraint should include the table name and if possible the owner (as long as you use user_* views the owner is always the same. But we could extend this to the ALL_* views). I never met a system where different tables have the identical FK constraint names, however just make this fool proof.</li> -
my following tables not allow me to delete the parent table student and the corperate recode in child table also get delete , why
create table Student( student_id int(10) not null , sure_name VARCHAR(25) not null, english_name Varchar(25) default null, chinese_name varchar(35) CHARACTER SET utf8 COLLATE utf8_general_ci not NULL, student_hkid varchar(12) not null, address varchar(100) default null, mobile_No varchar(15) default null, home_Telephone varchar(15) default null, email varchar(20) not null, faculty varchar(70) default null, department varchar(100) default null, local_student varchar(3) default 'No', fresh_student varchar(3) default 'No', fulltime_student varchar(3) default 'No', first_Ustudent varchar(3) default 'No', userIp VARCHAR(45) not NULL, accessTime VARCHAR(45) not NULL, primary key(student_id))TYPE=MyISAM CHARACTER set utf8; create table Student_financial_info( student_id int(10) not null, grant_loan varchar(3) default 'No', uploadfile text default null, notification_time varchar(10) default null, father_name varchar(25) default null, father_HKID varchar(12) default null, father_Salary decimal(6,2) , father_live_together varchar(3), mother_name varchar(25) default null, mother_HKID varchar(12) default null, mother_Salary decimal(6,2) , mother_live_together varchar(3), 1th_sibling_name varchar(25) default null, 1th_sibling_HKID varchar(12) default null, 1th_sibling_Salary decimal(6,2) , 1th_sibling_together varchar(3), 2th_sibling_name varchar(25) default null, 2th_sibling_HKID varchar(12) default null, 2th_sibling_Salary decimal(6,2) , 2th_sibling_together varchar(3), 3th_sibling_name varchar(25) default null, 3th_sibling_HKID varchar(12) default null, 3th_sibling_Salary decimal(6,2) , 3th_sibling_together varchar(3), 4th_sibling_name varchar(25) default null, 4th_sibling_HKID varchar(12) default null, 4th_sibling_Salary decimal(6,2) , 4th_sibling_together varchar(3), addition_income Varchar(200) default null, primary key(student_id ), FOREIGN KEY(student_id) REFERENCES student(student_id) ON DELETE CASCADE ON UPDATE CASCADE)TYPE=MyISAM CHARACTER set utf8;HJava wrote:
hi thank you!
I change my table Engine under Mysql Query Browser, but Foreign Key settinis not action at all ( thank you you mention the foreign key is ignore), quite stronge for me, I have to drop the table and change the table engine to InnoDB in my create table code and run it under command line client,
now, It work.
are there any different to use command line Client and Mysql Query Brower?
thank you!Not really, other than appearance. But, the "GUI" might let you simply change the type of table on an already created database (I don't know, haven't tried it), unfortunately, that won't activate any foreign keys when changing a MyISAM to InnoDB (although it will destroy keys on an InnoDB when changing to MyISAM), as, like the above quote says, the keys are not only not used, they are not even stored. I.E. MySQL no longer even knows, nor cares, that you even attempted to create a foreign key for that table. So, you must drop and recreate the table, you can't simply "change" it. Although you could change it (if the GUI even does this) and then add the foreign key constraints. -
Add a on delete cascade option
Hello,
the developer here ask me to add a "ON delete cascade" to some tables in the database. Some of them have around 30 child tables. I want to know how to do it. Is it just an alter table or I have to drop the foreing keys and re-create it?
Thanks
Jp
I'm on Oracle 10.2.0.4 on windows 2008 x64Hi,
I agree with Robert what he said, if you try to modify the constraint you will get the Issue
ORA-02275: such a referential constraint already exists in the tableMODIFY CONSTRAINT clause can only modify the state of a constraint either Enable or Disable.
- Pavan Kumar N
Oracle 9i/10g - OCP
http://oracleinternals.blogspot.com/ -
Foreign keys without ON DELETE CASCADE; Database Design question
This is the 3rd company i am working, where i see Foreign Keys created without
ON DELETE CASCADEclause.
My colleague says that it is created without ON DELETE CASCADE clause in order to make deletion of data (child records) difficult. So, for Purge/Archive codes, before we delete from Parent table we have to delete from the Child table first.
Occasinaly , something goes wrong and we'll end up disabling all FKs and then do Purging, Archiving, etc..
So, isn't it better to create Foreign keys with ON DELETE CASCADE clause rather than having all these hassles?
From you experience, what do you guys think?ON DELETE CASCADE is usually not a good idea - something 'magical' happens in the background and rows go away. Instead, consider making the FK DEFERRABLE INITIALLY DEFERRED. That way you can delete the parent and child rows in any sequence and the constraint will not be checked until commit time. You want to use an API (stored procedure/package) to make sure DML is executed in the proper sequence and in the proper way for your business rules.
-
Hai
i have 70 tables integrated with foreign and child key constraints. i have on delete cascade for all the child tables. if i delete the parent table automatically child table record get deleted.
Kindly tell me how can i check howmany child record has been deleted ..? how can i monitor this...?
one thing i can do... i can make count of child table before and after...
is there anyother way..?
SPeter,
I subscribe to the general consensus around trigger usage. Allthough I allways diffentiate between triggers that,
- perform pl/sql with embedded DML (that is: delete, insert, update)
versus triggers
- that perform pl/sql with embedded queries only.
The latter use of triggers is good (in my opinion), and most frequently used to enforce (non declarable) data integrity constraints.
The former use of triggers is bad. Because it makes things happen automagically.
Just google "asktom triggers are evil", you'll find statements such as:
~quote
because things happen automagically
because side effects are bad
because explicit linear code is more maintainable then "happens as a by product of something in the background"
magic should be avoided. Experience tells me this.
~quote
And to me a CASCADE DELETE clause on a foreign key definition, is a TRIGGER. Allbeit not one for which you had to write CREATE TRIGGER statements, but one that you can declaratively introduce. And this trigger holds embedded DML, it is of the former case, and is therefor bad.
You the designer of the application may be aware that you have your FK's as cascade delete. But your successor(s) might not be aware of this when they write maintenance code to delete Orders. They might be expecting the database to throw them an FK violation message when they try to delete an Order that still has Lines attached to it.
Everybody knows the effect of an INSERT, a DELETE, an UPDATE. But the moment you've introduced triggers with embedded DML in them, the effect of these three well known primitive SQL statements suddenly becomes unknown. With triggers you can create any effect for any of these three primitives, that you want. And more often than not other people maintaining your codebase later on in the future, do not realize these side effects happen, because they didn't check the presence of any triggers, nor investigated the side effects caused by them.
Btw. for exactly the same reasoning I consider use of DEFAULT-clause on table columns, or even use of (fixed length) CHAR datatype, evil also. Again they are in effect declarative triggers with side effects. Allbeit that their side effects usually are less worse than those caused by handwritten triggers with embedded DML.
Toon -
ORA-02292: integrity constraint - foreign key delete
I am getting the above error message when attempting to delete an entry with a foreign key constraint. I have the standard delete button and the standard DML process for inset, update, delete, and a page validation conditioned on the delete button for EXISTS with the following code:
select 1 from dual
where (select count(*) from mdeccommitments
where producer = :P25_COREID
and receiver = :P25_COREID) = 0
and (select count(*) from mdecbriefcal
where primarytarget = :P25_COREID
and primaryowner = :P25_COREID) = 0
This code works in SQL directly. However, when I try to run this, I do not get the inline error associated with the validation routine, I just get the popup for the delete and then the very user-unfriendly Oracle error, almost as if the validation wasn't there. I tried removing the popup associated with the delete button, but it did not make a difference.
I want to provide a friendly intercept and return. I do not want to cascade the delete. What am I missing here?
Thanks.
GillianThanks Varad, by running the debug, I realized I misinterpreted what the validation did - I had used EXISTS instead of NOT EXISTS. Making this change resulted in the correct processing. Being a newbie, I wasn't sufficiently familiar with the debug option to think about it.
-
Expdp seems to be inconsistent with multiple on delete cascade foreign keys
Hi,
I've raised an SR for this with Oracle already and am waiting for a reply but in the mean time i was hoping someone could give me a hint about something we're doing that is obviously wrong or if anyone else is aware of similar issues. The steps we are following are these:
1) 10.2.0.4.0 source system on SLES10 - we are doing a full schema level export using
FLASHBACK_TIME="to_timestamp(to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS')"
This should guarantee us a consistent export of the schema at the closest SCN to that timestamp
We get no errors during the export
2) we copy that file to a destination box which is 11.2.0.3.1 on SLES10
3) we import that file - all the table data loads fine and the row counts are the same as those in the export log.
4) when datapump reached the FK constraints 6 of them woouldn't enable with 'parent keys not found'
The 6 FK's in question are all on delete cascade references back to the same parent table, there are a further 3 child tables which also reference back to the same parent table (all on the same parent PK single column) which do enable OK. The parent rows are indeed not there. In live those rows no longer exist. It appears as if the extract has been don ehalf way between the parent being deleted and the children then being deleted - but i didn't think this would be possible with a 'consistent' datapump export?
So my question is how is this possible?
All i can think is:
a) the tables are being extracted a slightly different scn's due to some datapump bug?
b) on delete cascade actions are somehow in a different scn to the initial delete from the parent table (seems unlikely)
Can anyone shed any light on this?
Regards,
HarryHi Srini,
Here you go:
Export command
DIRECTORY=pumpy2
DUMPFILE=expdp_eltp_tp_prod_464.dmp
logfile=expdp_eltp_tp_prod_464.log
SCHEMAS=TP_PROD
PARALLEL=2
USERID=xx/xx
STATUS=120
FLASHBACK_TIME="to_timestamp(to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS')"
first bit of log
Export: Release 10.2.0.4.0 - 64bit Production on Monday, 20 August, 2012 11:14:54
Copyright (c) 2003, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": parfile=expdp_eltp_tp_prod_464.par
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 147.6 GB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TYPE/TYPE_SPEC
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/SEQUENCE/GRANT/OWNER_GRANT/OBJECT_GRANT
last bit of log
. . exported "TP_PROD"."ASSET_RESTRICTION" 0 KB 0 rows
. . exported "TP_PROD"."QRTZ_BLOB_TRIGGERS" 0 KB 0 rows
. . exported "TP_PROD"."QRTZ_CALENDARS" 0 KB 0 rows
. . exported "TP_PROD"."QRTZ_FIRED_TRIGGERS" 0 KB 0 rows
. . exported "TP_PROD"."QRTZ_JOB_LISTENERS" 0 KB 0 rows
. . exported "TP_PROD"."QRTZ_PAUSED_TRIGGER_GRPS" 0 KB 0 rows
. . exported "TP_PROD"."QRTZ_SCHEDULER_STATE" 0 KB 0 rows
. . exported "TP_PROD"."QRTZ_TRIGGER_LISTENERS" 0 KB 0 rows
. . exported "TP_PROD"."SQLN_EXPLAIN_PLAN" 0 KB 0 rows
. . exported "TP_PROD"."TPPRD_FUEL_SPLITS_BACKUP_STATS" 0 KB 0 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/oracle/ELUMPS/flashback/ELTP_datapump/expdp_eltp_tp_prod_464.dmp
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at 13:08:43
import command
impdp / directory=FROMLIVE transform=oid:n transform=segment_attributes:n remap_schema=TP_PROD:TP_INT_DEMO remap_tablespace=TP_DATA:tpcons_comp parallel=4 dumpfile=expdp_eltp_tp_prod_464.dmp remap_tablespace=temp01:temp
First bit of log
Import: Release 11.2.0.3.0 - Production on Mon Aug 20 18:04:43 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning option
Master table "ORACLE"."SYS_IMPORT_FULL_03" successfully loaded/unloaded
Starting "ORACLE"."SYS_IMPORT_FULL_03": /******** directory=FROMLIVE transform=oid:n transform=segment_attributes:n remap_schema=TP_PROD:TP_INT_DEMO remap_tablespace=TP_DATA:tpcons_comp parallel=4 dumpfile=expdp_eltp_tp_prod_464.dmp remap_tablespace=temp01:temp
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TYPE/TYPE_SPEC
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/SEQUENCE/GRANT/OWNER_GRANT/OBJECT_GRANT
last bit of log
ORA-39083: Object type JOB failed to create with error:
ORA-00001: unique constraint (SYS.I_JOB_JOB) violated
Failing sql is:
BEGIN SYS.DBMS_IJOB.SUBMIT( JOB=> 103, LUSER=> 'TP_INT_DEMO', PUSER=> 'TP_INT_DEMO', CUSER=> 'TP_INT_DEMO', NEXT_DATE=> TO_DATE('2012-08-20 11:40:08', 'YYYY-MM-DD:HH24:MI:SS'), INTERVAL=> '(sysdate + (1/(24*2))) ', BROKEN=> FALSE, WHAT=> 'dbms_refresh.refresh(''"TP_PROD"."TP_LEVEL"'');', NLSENV=> 'NLS_LANGUAGE=''AMERICAN'' NLS_TERRITORY=''AMERICA'' NLS_CURRENCY=''$'' NLS_ISO_CURREN
ORA-39083: Object type JOB failed to create with error:
ORA-00001: unique constraint (SYS.I_JOB_JOB) violated
Failing sql is:
BEGIN SYS.DBMS_IJOB.SUBMIT( JOB=> 104, LUSER=> 'TP_INT_DEMO', PUSER=> 'TP_INT_DEMO', CUSER=> 'TP_INT_DEMO', NEXT_DATE=> TO_DATE('2012-08-20 19:08:56', 'YYYY-MM-DD:HH24:MI:SS'), INTERVAL=> 'sysdate + 1', BROKEN=> FALSE, WHAT=> 'TP_PROD.SP_DELETE_MODEL_SCENARIO_DATA;', NLSENV=> 'NLS_LANGUAGE=''AMERICAN'' NLS_TERRITORY=''AMERICA'' NLS_CURRENCY=''$'' NLS_ISO_CURRENCY=''AMERICA'' NLS_NU
Processing object type SCHEMA_EXPORT/REFRESH_GROUP
ORA-39083: Object type REFRESH_GROUP failed to create with error:
ORA-01435: user does not exist
ORA-06512: at "SYS.DBMS_IREFRESH", line 85
ORA-01403: no data found
Failing sql is:
BEGIN dbms_refresh.make('"TP_PROD"."TP_LEVEL"',list=>null,next_date=>null,interval=>null,implicit_destroy=>TRUE,lax=>FALSE,job=>103,rollback_seg=>NULL,push_deferred_rpc=>TRUE,refresh_after_errors=>FALSE,purge_option => 1,parallelism => 0,heap_size => 0);
dbms_refresh.add(name=>'"TP_PROD"."TP_LEVEL"',list=>'"TP_PROD"."TP_LEVEL"',
Job "ORACLE"."SYS_IMPORT_FULL_03" completed with 47 error(s) at 01:32:09There were various errors about grants and jobs but nothing that would affect the table data and the fk constraints. The row counts exactly match between the parent and child tables in the export and import logs - so it looks like whatever the issue is happened at the 10.2.0.4 end.
Cheers,
Harry -
Primary key constraint for index-organized tables or sorted hash cluster
We had a few tables dropped without using cascade constraints. Now when we try to recreate the table we get an error message stating that "name already used by an existing constraint". We cannot delete the constraint because it gives us an error "ORA-25188: cannot drop/disable/defer the primary key constraint for index-organized tables or sorted hash cluster" Is there some sort of way around this? What can be done to correct this problem?
What version of Oracle are you on?
And have you searched for the constraint to see what it's currently attached to?
select * from all_constraints where constraint_name = :NAME; -
Can't Delete Parent Record - On Delete Cascade is set
Greetings all,
I have a parent and child table and when I attempt to delete the parent record, I get the following error:
ORA-02292: integrity constraint (WFSTEADMAN.INCIDENT_NOTES_TBL_FK) violated - child record found
Error Unable to process row of table MYTEST_INCIDENTS.
I have the the FK set to ON DELETE CASCADE so I am not sure what the issue might be.
Below are the structures of my parent and child tables:
I am using apex.oracle.com so the version is: Application Express 4.0.2.00.06
Any assistance would be appreciated.
Wally
PARENT TABLE:
=============================================================
CREATE TABLE "MYTEST_INCIDENTS"
( "INCIDENTID" NUMBER NOT NULL ENABLE,
"INCIDENTCREATED" DATE NOT NULL ENABLE,
"INCIDENT_OWNER" VARCHAR2(200) NOT NULL ENABLE,
"DTGSTART" DATE NOT NULL ENABLE,
"DTGEND" DATE,
"INCIDENT_SERVICES" VARCHAR2(4000),
"INCIDENT_CUSTOMERS" VARCHAR2(4000),
"INCIDENT_DESCRIPTION" VARCHAR2(4000),
"INCIDENT_TIMELINE" VARCHAR2(4000),
"INCIDENT_TRACKING" VARCHAR2(500),
"INCIDENT_RESTORE" VARCHAR2(4000),
"INCIDENT_FOLLOWUP" VARCHAR2(4000),
"INCIDENT_LEVEL" NUMBER,
"INCIDENT_TITLE" VARCHAR2(500),
"EMAIL_NOTIFY" VARCHAR2(4000),
"TEXT_NOTIFY" VARCHAR2(4000),
"LEVEL_TYPE" VARCHAR2(25),
CONSTRAINT "MYTEST_INCIDENTS_PK" PRIMARY KEY ("INCIDENTID") ENABLE
CREATE OR REPLACE TRIGGER "BI_MYTEST_INCIDENTS"
before insert on "MYTEST_INCIDENTS"
for each row
begin
if :NEW."INCIDENTID" is null then
select "MYTEST_INCIDENTS_SEQ".nextval into :NEW."INCIDENTID" from dual;
end if;
end;
ALTER TRIGGER "BI_MYTEST_INCIDENTS" ENABLE;
CHILD TABLE
=============================================================
CREATE TABLE "MYTEST_INC_NOTES"
( "NOTEID" NUMBER NOT NULL ENABLE,
"INCIDENT_ID" NUMBER NOT NULL ENABLE,
"NOTE_DTG" DATE,
"NOTE_OWNER" VARCHAR2(200),
"NOTE_COMMENTS" VARCHAR2(4000),
CONSTRAINT "MYTEST_INC_NOTES_PK" PRIMARY KEY ("NOTEID") ENABLE
) ;ALTER TABLE "MYTEST_INC_NOTES" ADD CONSTRAINT "MYTEST_INC_NOTES_CON" FOREIGN KEY ("INCIDENT_ID")
REFERENCES "MYTEST_INCIDENTS" ("INCIDENTID") ON DELETE CASCADE ENABLE;
CREATE OR REPLACE TRIGGER "BI_MYTEST_INC_NOTES"
before insert on "MYTEST_INC_NOTES"
for each row
begin
if :NEW."NOTEID" is null then
select "MYTEST_INC_NOTES_SEQ".nextval into :NEW."NOTEID" from dual;
end if;
end;
ALTER TRIGGER "BI_MYTEST_INC_NOTES" ENABLE;
CREATE OR REPLACE TRIGGER "MYTEST_INC_NOTES_T1"
BEFORE
insert or update on "MYTEST_INC_NOTES" REFERENCING NEW AS NEW OLD AS OLD
for each row
begin
:NEW.NOTE_DTG := SYSDATE;
end;
ALTER TRIGGER "MYTEST_INC_NOTES_T1" ENABLE;Yeah there was a rampant child table still left out there. Noticed the issue and deleted the child and all is well now. :). Should have looked for a couple more minutes before posting.
Thanks
Wally
Maybe you are looking for
-
What is the use of Alternative Calculation Type =2 and 4
Dear Friends In pricing procedure in gross value, Net value for Item and Net value has Alternative calucation type is 2. What is the use of it? Without using it these value line are also fetching net value then what is the work of it. Please give me
-
Last night I updated my ios from 5 to 7.1.1 on my iPhone 4s. Ever since, I have had no microphone use in Siri, texting, or Notes. But the microphone DOES work fine on the phone and in Dragon. When I am in a text message, and I press the microphone
-
SAP Netweaver CE 7.1 EHP1 for Windows 32bit
Hello, anybody knows where I can download a SAP Netweaver CE 7.1 EHP1 for Windows 32bit? At the SAP Software Distribution Center I have found only 64bit version. Günter
-
I have a wireless network/internet connection setup in my house. I have Wireless G Linksys Router sending my 10mb Internet signal to my Laptop PC and G5 Mac, the internet works fine, great speeds on both pc and mac, however... When i try and transfer
-
Is my account working now