How i can solve ORACLE problem in foreign key





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I have a problem in oracle and I need help. I have the following query:



1 CREATE TABLE TEST1 (
2 NAME VARCHAR(20)
3 ID VAR(9)
4 PRIMARY KEY(ID)
5 FOREIGN KEY(NAME) References TEST2(ANAME)
6 ON DELETE CASCADE ON UPDATE SET NULL );


If I want to delete line #6 what should i do?










share|improve this question

























  • ON UPDATE CASCADE is not valid in Oracle, So, just edit your statement to remove that clause.

    – APC
    Nov 23 '18 at 14:44











  • If you want to delete line #6, then just delete it. What exactly is your question?

    – a_horse_with_no_name
    Nov 23 '18 at 14:48











  • How I can change the value of primary key and based of that the foreign keys of this pk will change too ??

    – Hailah
    Nov 23 '18 at 15:33


















1















I have a problem in oracle and I need help. I have the following query:



1 CREATE TABLE TEST1 (
2 NAME VARCHAR(20)
3 ID VAR(9)
4 PRIMARY KEY(ID)
5 FOREIGN KEY(NAME) References TEST2(ANAME)
6 ON DELETE CASCADE ON UPDATE SET NULL );


If I want to delete line #6 what should i do?










share|improve this question

























  • ON UPDATE CASCADE is not valid in Oracle, So, just edit your statement to remove that clause.

    – APC
    Nov 23 '18 at 14:44











  • If you want to delete line #6, then just delete it. What exactly is your question?

    – a_horse_with_no_name
    Nov 23 '18 at 14:48











  • How I can change the value of primary key and based of that the foreign keys of this pk will change too ??

    – Hailah
    Nov 23 '18 at 15:33














1












1








1








I have a problem in oracle and I need help. I have the following query:



1 CREATE TABLE TEST1 (
2 NAME VARCHAR(20)
3 ID VAR(9)
4 PRIMARY KEY(ID)
5 FOREIGN KEY(NAME) References TEST2(ANAME)
6 ON DELETE CASCADE ON UPDATE SET NULL );


If I want to delete line #6 what should i do?










share|improve this question
















I have a problem in oracle and I need help. I have the following query:



1 CREATE TABLE TEST1 (
2 NAME VARCHAR(20)
3 ID VAR(9)
4 PRIMARY KEY(ID)
5 FOREIGN KEY(NAME) References TEST2(ANAME)
6 ON DELETE CASCADE ON UPDATE SET NULL );


If I want to delete line #6 what should i do?







oracle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 14:48









AlpacaFur

163211




163211










asked Nov 23 '18 at 14:31









HailahHailah

61




61













  • ON UPDATE CASCADE is not valid in Oracle, So, just edit your statement to remove that clause.

    – APC
    Nov 23 '18 at 14:44











  • If you want to delete line #6, then just delete it. What exactly is your question?

    – a_horse_with_no_name
    Nov 23 '18 at 14:48











  • How I can change the value of primary key and based of that the foreign keys of this pk will change too ??

    – Hailah
    Nov 23 '18 at 15:33



















  • ON UPDATE CASCADE is not valid in Oracle, So, just edit your statement to remove that clause.

    – APC
    Nov 23 '18 at 14:44











  • If you want to delete line #6, then just delete it. What exactly is your question?

    – a_horse_with_no_name
    Nov 23 '18 at 14:48











  • How I can change the value of primary key and based of that the foreign keys of this pk will change too ??

    – Hailah
    Nov 23 '18 at 15:33

















ON UPDATE CASCADE is not valid in Oracle, So, just edit your statement to remove that clause.

– APC
Nov 23 '18 at 14:44





ON UPDATE CASCADE is not valid in Oracle, So, just edit your statement to remove that clause.

– APC
Nov 23 '18 at 14:44













If you want to delete line #6, then just delete it. What exactly is your question?

– a_horse_with_no_name
Nov 23 '18 at 14:48





If you want to delete line #6, then just delete it. What exactly is your question?

– a_horse_with_no_name
Nov 23 '18 at 14:48













How I can change the value of primary key and based of that the foreign keys of this pk will change too ??

– Hailah
Nov 23 '18 at 15:33





How I can change the value of primary key and based of that the foreign keys of this pk will change too ??

– Hailah
Nov 23 '18 at 15:33












1 Answer
1






active

oldest

votes


















0














"How I can change the value of primary key and based of that the foreign keys of this pk will change too?"



First, you should never need to do that. Primary keys like this are really just numbers that identify a row, they have no meaning in themselves. It's like asking how you would change the ROWID of a row.



If you must, you could:




  1. Find the foreign keys pointing to this table and disable them with ALTER CONSTRAINT myconstraint DISABLE

  2. Update your primary table and catch the new id value with UPDATE test1 SET id = mysequence.NEXTVAL WHERE id = :oldid RETURNING id INTO :newid, assuming it's set by a sequence.

  3. Update the ids in your other tables with the new id.

  4. Reenable your constraints.


Note that altering constraints is DDL and will do an implicit commit and this approach will leave your tables unprotected by the foreign key constraints.



A second approach would be to:




  1. Insert a new row in the primary table and catch the new id.

  2. Update the id in the foreign tables with the new id.

  3. Delete the old row in the primary table.


Now that I think about it, that second approach seems better to me. No DDL and it just seems cleaner.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448557%2fhow-i-can-solve-oracle-problem-in-foreign-key%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    "How I can change the value of primary key and based of that the foreign keys of this pk will change too?"



    First, you should never need to do that. Primary keys like this are really just numbers that identify a row, they have no meaning in themselves. It's like asking how you would change the ROWID of a row.



    If you must, you could:




    1. Find the foreign keys pointing to this table and disable them with ALTER CONSTRAINT myconstraint DISABLE

    2. Update your primary table and catch the new id value with UPDATE test1 SET id = mysequence.NEXTVAL WHERE id = :oldid RETURNING id INTO :newid, assuming it's set by a sequence.

    3. Update the ids in your other tables with the new id.

    4. Reenable your constraints.


    Note that altering constraints is DDL and will do an implicit commit and this approach will leave your tables unprotected by the foreign key constraints.



    A second approach would be to:




    1. Insert a new row in the primary table and catch the new id.

    2. Update the id in the foreign tables with the new id.

    3. Delete the old row in the primary table.


    Now that I think about it, that second approach seems better to me. No DDL and it just seems cleaner.






    share|improve this answer




























      0














      "How I can change the value of primary key and based of that the foreign keys of this pk will change too?"



      First, you should never need to do that. Primary keys like this are really just numbers that identify a row, they have no meaning in themselves. It's like asking how you would change the ROWID of a row.



      If you must, you could:




      1. Find the foreign keys pointing to this table and disable them with ALTER CONSTRAINT myconstraint DISABLE

      2. Update your primary table and catch the new id value with UPDATE test1 SET id = mysequence.NEXTVAL WHERE id = :oldid RETURNING id INTO :newid, assuming it's set by a sequence.

      3. Update the ids in your other tables with the new id.

      4. Reenable your constraints.


      Note that altering constraints is DDL and will do an implicit commit and this approach will leave your tables unprotected by the foreign key constraints.



      A second approach would be to:




      1. Insert a new row in the primary table and catch the new id.

      2. Update the id in the foreign tables with the new id.

      3. Delete the old row in the primary table.


      Now that I think about it, that second approach seems better to me. No DDL and it just seems cleaner.






      share|improve this answer


























        0












        0








        0







        "How I can change the value of primary key and based of that the foreign keys of this pk will change too?"



        First, you should never need to do that. Primary keys like this are really just numbers that identify a row, they have no meaning in themselves. It's like asking how you would change the ROWID of a row.



        If you must, you could:




        1. Find the foreign keys pointing to this table and disable them with ALTER CONSTRAINT myconstraint DISABLE

        2. Update your primary table and catch the new id value with UPDATE test1 SET id = mysequence.NEXTVAL WHERE id = :oldid RETURNING id INTO :newid, assuming it's set by a sequence.

        3. Update the ids in your other tables with the new id.

        4. Reenable your constraints.


        Note that altering constraints is DDL and will do an implicit commit and this approach will leave your tables unprotected by the foreign key constraints.



        A second approach would be to:




        1. Insert a new row in the primary table and catch the new id.

        2. Update the id in the foreign tables with the new id.

        3. Delete the old row in the primary table.


        Now that I think about it, that second approach seems better to me. No DDL and it just seems cleaner.






        share|improve this answer













        "How I can change the value of primary key and based of that the foreign keys of this pk will change too?"



        First, you should never need to do that. Primary keys like this are really just numbers that identify a row, they have no meaning in themselves. It's like asking how you would change the ROWID of a row.



        If you must, you could:




        1. Find the foreign keys pointing to this table and disable them with ALTER CONSTRAINT myconstraint DISABLE

        2. Update your primary table and catch the new id value with UPDATE test1 SET id = mysequence.NEXTVAL WHERE id = :oldid RETURNING id INTO :newid, assuming it's set by a sequence.

        3. Update the ids in your other tables with the new id.

        4. Reenable your constraints.


        Note that altering constraints is DDL and will do an implicit commit and this approach will leave your tables unprotected by the foreign key constraints.



        A second approach would be to:




        1. Insert a new row in the primary table and catch the new id.

        2. Update the id in the foreign tables with the new id.

        3. Delete the old row in the primary table.


        Now that I think about it, that second approach seems better to me. No DDL and it just seems cleaner.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 23:06









        eaolsoneaolson

        8,79663247




        8,79663247
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448557%2fhow-i-can-solve-oracle-problem-in-foreign-key%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()