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.

Similar Messages

  • Drop foreign keys and recreate foreign keys with on delete cascade dymanica

    I need to drop foreign keys and recreate foreign keys with on delete cascade dymanically via a script. Does anyone have a script available?

    You could also disable the integrity contraints.
    SET PAGESIZE 0
    SET FEEDBACK OFF
    SET PAUSE OFF
    -- create a disable script
    SPOOL do_disable.sql
    SELECT 'ALTER TABLE '
           || table_name
            || chr(10) ||
           'DISABLE CONSTRAINT '
            || constraint_name
            || ';'
      FROM user_constraints
    WHERE constraint_type = 'R'
       AND status = 'ENABLED'
    select 'alter trigger '
           || trigger_name
            || ' disable;'
      from user_triggers
    where status = 'ENABLED'
    SPOOL OFF
    -- now create a enable script as well
    SPOOL do_enable.sql
    SELECT 'ALTER TABLE '
           || table_name
            || chr(10)
            || 'ENABLE CONSTRAINT '
            || constraint_name
            || ';'
      FROM user_constraints
    WHERE constraint_type = 'R'
       AND status = 'ENABLED'
    SELECT 'ALTER trigger '
           || trigger_name
            || ' ENABLE;'
      FROM user_triggers
    WHERE status = 'ENABLED'
    SPOOL OFF
    SET FEEDBACK ONif you run this script on a TESTdatabase you will end up with a do_disable.sql and a do_enable.sql script on youre local directory.
    Running do disable will disable all the currently enabled triggers and contraints.
    Running do_enable.sql will enable the previously disables triggers and contraints.
    be sure to test before executing this on a real live production database.
    Make sure you have a good backup!

  • Are foreign keys really necessary in a database design?

    Hi All,
    I am working on a database which has no foreign keys.
    Please suggest the necessity of foreign keys in database and can the foreign key implementation enhance the performance of the database.
    Thanks & Regards,
    Deepak Pushkarna

    [email protected] wrote:
    Hi Orion,
    As the application is a legacy application, so it has handled all the integrity part.Until someone touches the data outside the application. Can you spell "sqlplus"? Can you spell "odbc"?
    Or until some developer misses .... oh, developers never write buggy code ....
    >
    Regarding performance, the relation is not very complex but data is huge. So, if I implement foreign key relation, so will there be any improvement.
    It's really not about performance at all. It's about data integrity and data integrity is best protected by the dbms itself. In fact, the dbms is the only layer that you can be sure is going to protect your data integrity.
    >
    Thanks & Regards,
    Deepak Pushkarna

  • Hibernate: how to null out foreign key references when deleting an entity?

    We use Spring/Hibernate3 in our app, and ran into kind of a bummer of a problem. We have a relationship that is many-to-one (e.g. Student -> School). This is represented by a schoolId on the Student table. When we delete the school through the Hibernate layer, we are immediately receiving foreign key constraints because Hibernate does not null out the Students' schoolId columns where applicable.
    What we'd like to see happen is something like this:
    1. SchoolDAO.delete(id)
    Hibernate: UPDATE Student set schoolId = NULL where schoolId = ?
    Hibernate: DELETE from School where id = ?
    But what we're actually seeing is:
    1. SchoolDAO.delete(id)
    Hibernate: DELETE from School where id = ?
    And hence the foreign key constraints.
    Was wondering if someone else here has run into this. Someone on the Hibernate forums suggested using an Interceptor, but the Hibernate3 interceptors don't give us access to the Session to allow us to do a bulk update to null out these references. Apparently the interceptor javadoc says that the interceptor is basically there to change properties on the object in question and should not involve the session at all.
    We then looked at implementing an Event, and that worked, but was not called for every cascade deleted event. We have a lot of cascade activity in our database, so that was a little disappointing.
    We had briefly considered manually nulling out that FK in the DAO itself, but that would not work with the large amount of Hibernate driven cascade deletion that goes on in our app (Hibernate does not call our DAO every time it cascade deletes an entity).
    Would greatly appreciate any pointers on this subject. We're hoping that others have run into this as well.
    thanks.

    I'm not sure why you'd expect that given that there's
    not really an equivalent object oriented operation -
    if you want to relinquish the object in the OO scheme
    of things you have to null all the references to it;
    you can't just say "make everything that points to
    this object null".I can field that question. We came from EJB 2.x where in the event that you deleted a School entity bean using ejbRemove() you would see the following queries generated:
    UPDATE Student set schoolId = NULL where schoolId = ?
    DELETE from School where id = ?
    Basically, it would manage the relationship for you. I know it's a completely different system but we were a little surprised to learn that Hibernate did not do this on its own as well.

  • Using FOreign key constraints on tables in database.

    I am student and novice in the field of ORACLE and PL/SQL and Database Creation. I had created a database consisting tables and got problem while applying foreign key constraints.
    CUST_MSTR
    CREATE TABLE "DBA_BANKSYS"."CUST_MSTR"("CUST_NO" VARCHAR2(10),
    "FNAME" VARCHAR2(25), "MNAME" VARCHAR2(25), "LNAME" VARCHAR2(25),
    "DOB_INC" DATE NOT NULL,      "OCCUP" VARCHAR2(25), "PHOTOGRAPH" VARCHAR2(25),
    "SIGNATURE" VARCHAR2(25), "PANCOPY" VARCHAR2(1),      "FORM60" VARCHAR2(1));
    (CUST_NO is PRIMARY KEY, )
    -- EMP_MSTR
    CREATE TABLE "DBA_BANKSYS"."EMP_MSTR"("EMP_NO" VARCHAR2(10),
    "BRANCH_NO" VARCHAR2(10), "FNAME" VARCHAR2(25), "MNAME" VARCHAR2(25),
    "LNAME" VARCHAR2(25), "DEPT" VARCHAR2(30), "DESIG" VARCHAR2(30));
    (EMP_NO is primary key )
    --NOMINEE_MSTR
    CREATE TABLE "DBA_BANKSYS"."NOMINEE_MSTR"("NOMINEE_NO" VARCHAR2(10),
    "ACCT_FD_NO" VARCHAR2(10), "NAME" VARCHAR2(75), "DOB" DATE,
    RELATIONSHIP" VARCHAR2(25));
    (NOMINEE_NO is primary key )
    --ADDR_DTLS
    CREATE TABLE "DBA_BANKSYS"."ADDR_DTLS"("ADDR_NO" NUMBER(6),
    "CODE_NO" VARCHAR2(10),      "ADDR_TYPE" VARCHAR2(1), "ADDR1" VARCHAR2(50),
    "ADDR2" VARCHAR2(50), "CITY" VARCHAR2(25), "STATE" VARCHAR2(25),
    "PINCODE" VARCHAR2(6));
    ( ADDR_NO is primary key )
    Problem: I want to apply foreign key constraints on ADDR_DTLS table so that Before inserting value in ADDR_DTLS table it must check, VALUE in ADDR_DTLS.CODE_NO must be PRESENT either in attribute value CUST_MSTR.CODE_NO or EMP_MSTR.CODE_NO or NOMINEE_MSTR.CODE_NO table .
    I applied the foreign key constraints using this syntax
    CREATE TABLE "DBA_BANKSYS"."ADDR_DTLS"("ADDR_NO" NUMBER(6),
    "CODE_NO" VARCHAR2(10),      "ADDR_TYPE" VARCHAR2(1), "ADDR1" VARCHAR2(50),
    "ADDR2" VARCHAR2(50), "CITY" VARCHAR2(25), "STATE" VARCHAR2(25),
    "PINCODE" VARCHAR2(6),
    constraints fk_add foreign key CODE_NO references CUST_MSTR. CODE_NO,
    constraints fk_add1 foreign key CODE_NO references EMP_MSTR. CODE_NO,
    constraints fk_add2 foreign key CODE_NO references NOMINEE_MSTR.CODE_NO);
    (foreign key)
    ADDR_DTLS.CODE_NO ->CUST_MSTR.CUST_NO
    ADDR_DTLS.CODE_NO ->NOMINEE_MSTR.NOMINEE_NO
    ADDR_DTLS.CODE_NO ->BRANCH_MSTR.BRANCH_NO
    ADDR_DTLS.CODE_NO ->EMP_MSTR.EMP_NO
    When I applied foreign key constraints this way, its gives a error called foreign key constraints violation. (I understand that, its searches the attribute value of ADDR_DTLS.CODE_NO in all the three tables must be present then the value will be inserted. But I want, if the value is in any of the three table then its should insert the value or its gives an error.)
    Please help me out, though i put the question and i want too know how to apply the forign key in this way. and is there any other option if foreign key implementation is not pssible.

    If you are on 11g you can use ON DELETE SET NULL:
    CREATE TABLE addr_dtls
    ( addr_no          NUMBER(6)  CONSTRAINT addr_pk PRIMARY KEY
    , addr_cust_no     CONSTRAINT addr_cust_fk    REFERENCES cust_mstr    ON DELETE SET NULL
    , addr_emp_no      CONSTRAINT addr_emp_fk     REFERENCES emp_mstr     ON DELETE SET NULL
    , addr_nominee_no  CONSTRAINT addr_nominee_fk REFERENCES nominee_mstr ON DELETE SET NULL
    , addr_type        VARCHAR2(1)
    , addr1            VARCHAR2(50)
    , addr2            VARCHAR2(50)
    , city             VARCHAR2(25)
    , state            VARCHAR2(25)
    , pincode          VARCHAR2(6) );In earlier versions you'll need to code some application logic to do something similar when a parent row is deleted, as otherwise the only options are to delete the dependent rows or raise an error.
    btw table names can be up to 30 characters and don't need to end with MSTR or DTLS, so for example CUSTOMERS and ADDRESSES might be more readable than CUST_MSTR and ADDR_DTLS. Also if the Customer/Employee/Nominee PKs are generated from a sequence they should be numeric.
    Edited by: William Robertson on Aug 15, 2010 6:47 PM

  • Syntax for creating foreign key across users in a database

    There are two user present A,B.They are granted all privileges.Now in USER A, there is a table PARENT whose primary key is PARENT_NO.In USER B I have created a table CHILD whose primary key is CHILD_NO.
    In the CHILD table of USER B, I want to create a foreign key relation to the PARENT table of USER A.For this I have created a column CHILD_PARENT_NO in the CHILD table.If anybody knows the syntax please post the syntax for creating the required foreign key relationship?

    Please post your code. Cut'n'paste from SQL*Plus like this...
    SQL> conn a/a
    Connected.
    SQL> desc t1
    Name                                      Null?    Type
    COL1                                               NUMBER
    COL2                                               VARCHAR2(10)
    SQL> grant references on t1 to b;
    Grant succeeded.
    SQL> conn b/b
    SQL> create synonym a_t for a.t1;
    Synonym created.
    SQL> alter table test add constraint fk foreign key (n) references a_t(col1);
    Table altered.
    SQL> Note that Oracle will translate the synonym anyway...
    SQL> select constraint_name, r_owner, r_constraint_name
      2  from  user_constraints
      3  where table_name = 'TEST'
      4  /
    CONSTRAINT_NAME R_OWNER R_CONSTRAINT_NAME
    FK              A       T1_PK
    SQL> By the way, this ...
    GRANT ALL PRIVILEGES TO B;... is a mindbendingly unsafe way of proceeding. In real life you would have given user B the power to utterly destroy your database. It's always easier to start with good habits than to break bad ones so please get used to granting only the minimum set of privileges necessary.
    Cheers, APC

  • Foreign keys in source tables (sybase database)

    Hi,
    Foreign key / primary key constraints are not captured / converted in oracle model nor they are generated.
    I am migrating sybase database tables to oracle. These tables have foreign keys, but while capturing and then converting the table to oracle model and then generating, these foreign keys are not present in the ddl script.
    In the source connection ( in the tool) to the sybase database, these keys are shown,
    and logically when the generation is done for table, the foreign / primary key syntax should be present in the ddl generated
    Am more worried about the foreign key not getting converted
    Please help
    Regards

    Hello,
    do you have a very simple example showing this behaviour ?
    What is your sybase version ? And what about Sqldev version ?
    Do you tested migration with offline method ?
    As testcase, a emp and dept schema with foreign key should be ideal.
    Thanks
    Regards,
    Marcello

  • Database design question about historical data in a group of tables

    Hi Folks,
    I have a group of tables having relationships among them. In order to keep the change history, we can not update the data, instead, we add new data to the table(s) and mark older data as whatever non-current status. They all have timestamps in these tables.
    For example, If table Parent changes, we add new record Parent(new) and keep older record(s). But the table child has not changed, so how could we link the parent and child table(s)?
    One solution is to use a unique sequencial number to identify the snapshot of all these group of tables, so the FK contains this sequencial number to keep all tables in sync from point of time t1 to t2 and so on.
    But the problem is if only one table changes, we have to insert new records to ALL tables with the new sequencial number to indicate a new snapshot of all group of tables, this obviously has lots of redundancy when change occurs in one place only.
    However, If we only adds new records to a changed table, lets say Parent, how could we distinguish the current record in Parent table and its child tables to reflect a consistent snapshot of all tables? Because the record in parent table Parent(t2), Parent(t1) all associate to child(t1), since at time of t2, child table has not changed, only Parent table changed.
    Your opinions are appreciated!
    Thanks a lot.

    There are books on the subject of dealing with time series data. You may need to read one or two as this is a very complex topic. Though not applications of time series classification are complex it is difficult to tell based on what information can go in a post.
    What has to be reflected on the parent when a child row is changed? Do both the old child row and the new child row belong to the same parent?
    What activity at the parent level would affect the child rows? That is, is there any activty on the parent that requires new child rows to be populated?
    One way of tying the child rows to a specific set of parents would be to carry the parent key, timestamp to the child as a begin_parent_timestamp and then also potentially have a end timestamp if a change to a parent ends the relationship. If changes to the parent do not ever end the relationsip then the end_timestamp would not be necessary. In this case if you want to join a parent to only the most recent version of a child you can perform a select parent kye, child key, max(parent_timestamp) from child group by parent key, child key. One child row would match serveral parents.
    Without more specifics it is hard to make suggestions that might prove usable but your table relationships might be too complex to deal with in this kind of forum.
    There is a newsgroup on database theory that may be a good place to seek ideas on this type of problem.
    HTH -- Mark D Powell --

  • Clustering and database design question

    Hi,
              One of the things we are seeing with running clusters is that, reasonably,
              as we get more users (due to increased capacity of the cluster), we get more
              hits on the database. As these are now coming from multiple servers it is
              more likely they are in separate transactions and so are less coordinated.
              As a result, what we see, is more deadlocks at the database( Sybase 11.9.2).
              We have introduced row-level locking and this helps, also stored procedures
              have shown some improvement in really over-used tables, but I can't help
              thinking this is a general design concern.
              The way I have been intending to scale our cluster is to have identical
              server deployments of all beans and use load-balancing for the client
              connections to the cluster. However, all our cluster members will be using
              the same database so the chance of deadlocks must increase for each server I
              add.
              Is this a general design problem or are there design solutions I can adopt
              to help with this? Can anyone give some good advice, highlight specific
              weblogic features, discuss similar designs or point to some good documents
              on such scalability issues? Perhaps I should add the majority of our
              database access is by entity beans using bean managed persistence.
              Thanks
              Sioux
              

              Give TopLink a try:
              Clustering - Refresh Yes
              Ability to refresh cached beans and objects between nodes of a cluster of application
              servers
              Clustering - Synchronization Yes*
              TopLink WebLogic contains support for synchronous or asynchronous cache synchronization
              between nodes in a cluster. TopLink WebSphere cache synchronization will be supported
              01Q1
              Cocobase has a similar distributed caching scheme. But WebGain should be a better
              bet because they are 40% owned by BEA (better integration with WebLogic)
              Jim Zhou.
              "Mike Reiche" <[email protected]> wrote:
              >
              >
              ><whine>
              >I haven't seen a solution to this yet. Clustering prevents the application
              >server
              >from caching database data - which is the reason we use applications
              >in the first
              >place. All data is read from the db at the beginning of a transaction
              >and written
              >back at the end of a transaction.
              ></whine>
              >
              >We are trying to avoid this by pinning entity bean instances to a single
              >WL instance,
              >then we can set db-is-shared=false and the WL instance can cache the
              >entity bean.
              > Stateful session beans seem more suited to scaling than entity beans
              >- there
              >is only ever one instance of a session bean - if you access it from a
              >different
              >WL instance, it is accessed via RMI. For entity beans - multiple copies
              >exist
              >on the different servers.
              >
              >Read-only entity beans are ok if your data is truly read-only. Still,
              >each WL
              >instance will need to read the data from the DB and each copy of the
              >same entity
              >bean instance on each WL instance takes up memory. From the db's point
              >of view
              >- the more you scale, the worse things get. The only thing that WL clustering
              >scales is CPU. WL clustering does not really help to scale the number
              >of entity
              >beans instances.
              >
              >The Read-Mostly pattern exists - but I find this gives me the worst of
              >both worlds.
              >My beans are not always up-to-date and I have all these duplicate instances.
              >
              >Said that, I would love for someone from BEA to contradict me - and tell
              >me how
              >I can make entity beans scale in a WL cluster.
              >
              >
              >- Mike
              >
              >"Sioux France" <[email protected]> wrote:
              >>Hi,
              >>One of the things we are seeing with running clusters is that, reasonably,
              >>as we get more users (due to increased capacity of the cluster), we
              >get
              >>more
              >>hits on the database. As these are now coming from multiple servers
              >it
              >>is
              >>more likely they are in separate transactions and so are less coordinated.
              >>As a result, what we see, is more deadlocks at the database( Sybase
              >11.9.2).
              >>We have introduced row-level locking and this helps, also stored procedures
              >>have shown some improvement in really over-used tables, but I can't
              >help
              >>thinking this is a general design concern.
              >>The way I have been intending to scale our cluster is to have identical
              >>server deployments of all beans and use load-balancing for the client
              >>connections to the cluster. However, all our cluster members will be
              >>using
              >>the same database so the chance of deadlocks must increase for each
              >server
              >>I
              >>add.
              >>Is this a general design problem or are there design solutions I can
              >>adopt
              >>to help with this? Can anyone give some good advice, highlight specific
              >>weblogic features, discuss similar designs or point to some good documents
              >>on such scalability issues? Perhaps I should add the majority of our
              >>database access is by entity beans using bean managed persistence.
              >>Thanks
              >>Sioux
              >>
              >>
              >
              

  • 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
    Prafulla

    I 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;

  • Migration: sqlserver 2000 to oracle - delete cascade [resolved - tank you]

    hi
    no problems on migration... but...
    in the new oracle database, all foreign keys have the "cascade delete" as default...
    but i don't want this default (a stupid human error may be ruinous...)
    can somebody explain me how change this default in a "exception thrown"?
    maybe with an authomatic sql order????
    tank you a lot...
    Giovanni D.
    Message was edited by:
    user535473

    Hi Giovanni,
    Tools> Options> General
    Create Foreign Keys with "ON DELETE CASCADE" option
    Just untick the box and remap from the source to the oracle model.
    Hope this helps
    Dermot.

  • Cascade or delete in database server, why if my EJB do it for me??

    Hi,
    I am in design phase of a database for my j2EE application. In the database desing i have some relationships entities, that have foreign keys. I have several options about foreign keys in the relationships, cascade deletes, restrict .... all in my database server.
    But, when i am reading the referencial integrity of the entity EJBs CMP relationships, the entity beans make the cascade deletes automaticaly for maintain the relationsships.
    Need i make my relationships in my database server with cascade delete options or leave it for my application server???
    Another one, if i make relationships in my database server, why i need do it in my entity beans???
    tanks, sorry for my poor english

    Hi Markus,
    Tanks for your answer, if this tip only for entity beans with CMP???
    For example, if i have some entity beans, one with CMP and other with JDO, or for example, an entity beans that use CMP and JDO for access to few tables (i dont know that it is possible or it a good design), how can i design the relationships update/delete cascades in my database server, all entity beans persistence types support his referencial integrity ?? if this if true i think that i forget the relationships updates/deletes cascades in my database server.
    At this moment, i dont know what type of persistence i will use in my application server. I dont undertand yet wath approach i must follow, i design my database and after design my entity beans over this database or i must foget my database and beging with entity beans design first .... i have a big problem, i need read a lot of more.
    Something for help me???
    Very, very thanks

  • Before delete trigger and foreign key relationship

    Hi,
    I am analysing one database for migration. On one parent table there is before delete trigger , to delete records from child. Also there is foreign key relationship on child table for this parent table.
    When I am deleting a row from parent, message gets displayed as "there are child records found."
    I would like to know, if there is foreign key relatioship then delete trigger on parent does't work, what is exactly happening?

    Could you post that trigger code and the Oracle version as well?
    With basic assumptions, I can't reproduce what you have stated here.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> create table parent (id number primary key);
    Table created.
    SQL> create table child (id number);
    Table created.
    SQL> alter table child add constraint fk_parent foreign key (id) references parent;
    Table altered.
    SQL> create or replace trigger bdr_parent
      2  before delete on parent
      3  for each row
      4  begin
      5  delete from child where id = :old.id;
      6  end;
      7  /
    Trigger created.
    SQL> insert into parent (id) values (1);
    1 row created.
    SQL> insert into child (id) values (1);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> delete from parent where id = 1;
    1 row deleted.
    SQL> select * from parent;
    no rows selected
    SQL> select * from child;
    no rows selected
    SQL> rollback;
    Rollback complete.
    SQL> alter table child drop constraint fk_parent;
    Table altered.
    SQL> alter table child add constraint fk_parent foreign key (id) references parent on delete cascade;
    Table altered.
    SQL> delete from parent where id = 1;
    delete from parent where id = 1
    ERROR at line 1:
    ORA-04091: table SCOTT.CHILD is mutating, trigger/function may not see it
    ORA-06512: at "SCOTT.BDR_PARENT", line 2
    ORA-04088: error during execution of trigger 'SCOTT.BDR_PARENT'
    SQL>

  • What is the advantage of Foreign keys in database

    suppose if we do not have FK then what kind of advantage we could not avail. we can fetch data from two table by creating a relation in sql.....then why FK is required. thanks

    Hi Mou_kolkata
    Overall foreign keys are very useful for maintaining data integrity.
    A nice article written by Armando
    Prato at mssqltips.com explains
    about importance of FKs.
    Advantages and disadvantages of using Foreign keys was also discussed under the design section of msdn forums at.
    SQL Server > Database Design.
    Hope they are helpful.
    Thanks and Regards, Ibrahim Mehdi. MCSE-DataPlatform

  • 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
    Rgrds

    There 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

Maybe you are looking for

  • Remote Desktop Licensing on a virtual machine

    I want to move a small business to a hosted solution. If all applications live on a virtual machine then the best way for users to access them would be via remote desktop. Looking through Azure documentation I do see that RDP licenses are not include

  • I purchased v1 golf and it will not load on my 3g phone any solutions

    I purchased v1 golf and it will not load on my 3g phone any solutions

  • How to add external library in class path folder for use in Java call-out?

    Hi, I am working with Java callout component in OSB 12c using Jdeveloper. Thing is Jar what i am using to perform conversion of json to xml that using external libraries. When i have give reference of my project jar to java callout it doen't found ex

  • Time Stamp in Adobe

    When I save a file in PhotoShop or other Adobe products the time of the file is not in sync with my computer clock - it is 7 hours early. How do I reset the clock in Adobe? All other programs i.e.Word etc. are the correct time. Thanks

  • UDF for graphical mapping

    Hi, The following is my source structure : Recordset 1..1 -> Idoc 1..unbounded -> Segment 1..1 <Recordset> <Idoc> <segment>abcdefgh</segment> </Idoc> <Idoc> <segment>klmno</segment> </Idoc> </Recordset> I have a requirement where in I have to pass th