Update primary key with waterfall

Lets say I have 10 tables that have a foreign key defined, that everything points to a single table primary key.
Now, I want to update the value of the primary key to another value, and I want all 10 tables to get this new value in their columns FK.
Also, note also that some of these 10 tables can have this FK-value that is updated to PK-table.
I can do this task with a good script?

I would like to somehow in this way:
Update PkTable set
Pkcol=NewAvailableValue
CASCADE;
Right now I use the following approach:
1. from table "user_constraints" find FK constraints binded to the primary change being key to find the list of tables.
2 query each table if it has the PK value in their columns-FK, if has, then update the value allowed another PK-value.
3. Update PK-value of primary key column of the table to the new value.
4 validation.

Maybe this will be useful: Tom Kyte: UPDATE CASCADE PACKAGE

Tags: Database

Similar Questions

  • disable the primary key with waterfall

    Hello everyone,

    I just want to know
    1. What is the effect after we diasble cascade a constraint primary key with the option?
    2 should rebuild us the index after you have enabled the constraint? How?

    Please explain with an example...

    Thanx

    2 should rebuild us the index after you have enabled the constraint? How?

    The index will be re-created for you automatically when you enable constraint even once:

    SQL> create table t (i integer constraint t_pk primary key)
    /
    Table created.
    
    SQL> select index_name, uniqueness from user_indexes where table_name = 'T'
    /
    INDEX_NAME                     UNIQUENES
    ------------------------------ ---------
    T_PK                           UNIQUE
    1 row selected.
    
    SQL> alter table t disable primary key cascade
    /
    Table altered.
    
    SQL> select index_name, uniqueness from user_indexes where table_name = 'T'
    /
    no rows selected.
    
    SQL> alter table t enable primary key
    /
    Table altered.
    
    SQL> select index_name, uniqueness from user_indexes where table_name = 'T'
    /
    INDEX_NAME                     UNIQUENES
    ------------------------------ ---------
    T_PK                           UNIQUE
    1 row selected.
    
    SQL> drop table t
    /
    Table dropped.
    
  • Adding primary keys with javascript.

    I have a database that has no metadata.

    We have the primary key definitions in an external system.

    The primary key information are easy to get.

    I want to update the relational model (and display) with the primary key information.

    Is it possible to update the primary key of infromation in the model of the relationship of Javascript?

    Hello

    You can try to settle for your use:

    // get table name
    tname = ...;
    //get pk name
    pkname = ....;
    table = model.getTableSet().getByName(tname);
    if(table !=n ull){
    index = table.createIndex();
    index.setName(pkname);
    index.setPK(true);
    // get column name - should iterate in case of multi column PK
    cname = ...;
    column = table.getElementByName(cname);
    if(column != null){
      index.add(column);
    }
    table.setDirty(true);
    }
    

    Philippe

  • Primary key with PHPmysql database question

    I know that the update of the primary key is a taboo subject, but I have a newsletter subscription form set up that works perfectly, but I can't understand how to create the primary key.  I tried to use the subscriber email address (because its unique, but when trying to add a function to update, I realize that the e-mail address may have to be updated.)

    My question is how do I get a primary key that works when I'm relying on a form variable to create the folder and did so no control over the assignment of one?

    Is it possible to have one assigned automatically when a Subscriber clicks on the submit button?

    This is why it is always a good idea to use surrogate keys. You can just have the database generates a unique id. In MySQL, I think that there is a column with the auto_increment attribute. If you then get this id after insert, php has functions for this (mysql_insert_id() I think).

  • updated primary key of the problem 10 gr 2 (10.1.2.0.1)

    Primary key can be updated... How to protect

    iloveoracle wrote:
    Primary key can be updated...

    Yes - longer updating does not violate constraint primary key

    How to protect

    Trigger.

  • A composite primary key with two KeyField: a rope and a sequential int.

    Hi all

    According to [url http://download.oracle.com/docs/cd/E17277_02/html/java/com/sleepycat/persist/model/PrimaryKey.html#sequence ()] sequence JavaDoc: a composite key class can also be used to substitute the sort order, but it can contain only a single key field which has one of the types mentioned previously.

    We strive to create a composite PK as follows:
    @Persistent
    public class ExamplePK {
        @KeyField(1) Integer seq;
        @KeyField(2) String admon;
    
        public String getAdmon() {
            return admon;
        }
    
        public void setAdmon(final String admon) {
            this.admon = admon;
        }
          public Integer getSeq() {
          return seq;
        }
          public void setSeq(final Integer seq) {
          this.seq = seq;
        }
    }
    
    @Entity
    public class ExamplePojo {
    
        // Relational fields
        @PrimaryKey(sequence="ExampleSeq")
        private ExamplePK idExample;
    
        public ExamplePK getIdExample() {
            return idExample;
        }
    
        public void setIdExample(final ExamplePK idExample) {
            this.idExample = idExample;
        }
    }
    but we get the following exception:
    java.lang.IllegalArgumentException:A composite key class used with a sequence may contain only a single integer key field: es.correos.ape.dao.notification.pojo.ExamplePK[Server1:1291138230743]
          at com.sleepycat.persist.impl.CompositeKeyFormat.getSequenceKeyFormat(CompositeKeyFormat.java:292)
          at com.sleepycat.persist.impl.PersistKeyAssigner.<init>(PersistKeyAssigner.java:39)
          at com.sleepycat.persist.impl.Store.getPrimaryIndex(Store.java:337)
          at com.sleepycat.persist.EntityStore.getPrimaryIndex(EntityStore.java:307)
    What we're doing wrong?

    ARO
    / Caesar.

    Caesar, I think that the wording of the javadoc and exception message is incorrect or at least confused, and I answer key for a future version.

    -mark

  • Two constraints of primary key of a table with two different constraint name

    Hi guys

    I am creating the table below

    Table name: TITLE_COPY

    Column name Copy_id Title_id Status

    Key type

    PKPK, FK
    UniqueNN, UNN, UNN
    CheckAvailable, destroyed, leased, reserved
    Table Ref FKTitle
    FK Ref ColTitle_id
    Data typeNumberNumberVarchar2
    Length101015

    The SQL statement below can create it

    CREATE TABLE title_copy (copy_id NUMBER (10),)

    title_id CONSTRAINT NUMBER (10) title_copy_title_id_fk title (title_id) REFERENCES.

    primary key constraint title_copy_title_id_pk title_id (copy_id)

    status VARCHAR2 (15) NOT NULL CONSTRAINT status_ck CHECK (status IN ('AVAILABLE', 'DESTROYED', 'RENTAL', 'RESERVED'))

    );

    Two primary keys (title_id, copy_id) are created with the same name of constraint (title_copy_title_id_pk) (-> table-level constraint). What happens if I want to have two different names of the primary key constraint, say title_copy_title_id_pk for the title_id column and title_copy_copy_id_pk for the copy_id column?

    I can do that with a column-level constraint? Something like below (complains about the additional primary key)

    CREATE TABLE title_copy (copy_id NUMBER (10) CONSTRAINT title_copy_copy_id_pk PRIMARY KEY,)

    constraint title_copy_title_id_pk primary key (title_id).

    title_id CONSTRAINT NUMBER (10) title_copy_title_id_fk title (title_id) REFERENCES.

    status VARCHAR2 (15) NOT NULL CONSTRAINT status_ck CHECK (status IN ('AVAILABLE', 'DESTROYED', 'RENTAL', 'RESERVED'))

    );

    In summary, I can define two primary keys with the name of different constraint in a column-level constraint?

    There are no two primary keys. There is a primary key made up of two columns - also called a composite key.

    A table can have at least a primary key. You can, if you wish, create a unique constraint on a different set of columns.

  • change a composite primary key


    Hello

    I have a table that has a composite primary key with 3 columns (col1, col2, col3)

    Now I need to change the primary key (col1, col2, col4) remove composite col3 replace with col4

    col1 col2 COL3 COL4 col5
    1onexpDFD
    1oneTherepDFD
    1onezpSD
    1onempamplifier
    1onenpTry

    There are thousands of records in the table in the format above. How to make this change?

    Thank you.

    In this case, you will need to establish that if the change to the primary key makes sense - if so, you'll have to remove some lines to remove duplicates. I think that if this requirement has been raised at a request of the company, they will (should) have indicated what lines need to be maintained.

    If it is not sensible, you will need to go to the one who asked for the change and get them to change their mind or tell you what to do with duplicate lines.

    Out of curiosity, why did you change the primary key?

  • Update line programmatically with Composite primary keys

    Hi all

    I use JDeveloper 11.1.2.4.0,I want to update the program with two primary keys PK1_ID and PK2_ID line

    When I have a primary key I can do it by:

    /////////////////////////////////////////////////////

    Key = new key (new Object() {empid});

    Employees1ViewImpl vo = (Employees1ViewImpl) this.getEmployees1View1 ();

    Locate the line using key reference in the View object.

    Line k = vo.getRow (key);

    using this method, we can set the new FirstName

    k.setAttribute ("FirstName", "Vero");

    this.getDBTransaction () .commit ();

    ///////////////////////////////

    Is it possible to use the same code with more of primary key?




    Kind regards

    The key class contains an array of attributes that identify the line you're looking for. In your case, the key has two attributes

    Key = new key (new Object() {pkId1, pkId2});

    the rest of the method works as what.

    Timo

  • Update a table with primary key

    Hello

    I have a table called Temp

    CREATE TABLE TEMP
    (
       A   VARCHAR2 (50 CHAR),
       B   VARCHAR2 (50 CHAR),
       C   VARCHAR2 (50 CHAR),
       D   VARCHAR2 (18 CHAR),
       E   DATE,
       F   NUMBER,
       G   VARCHAR2 (18 CHAR),
       H   FLOAT
    );
    

    The primary key is the PRIMARY KEY: (A, B, C, D, E, F, G).

    I HAVE THE TEMPORARY TABLE 48052365 COUNTY,

    HOWEVER I HAVE A REQUIREMENT TO UPDATE WHERE E (COLUMN) IS WEDNESDAY, THE SAME DAY IN MONDAY (I.E., C - 2 TO EXISTING DATE)

    Approach;

    I CREATED the TABLE TEMP_WED_TO_MONDAY AND SELECTED ALL THE RECORDINGS ELIGIBLE IN CE AND TABLE AND INDEX UNIQUE CREATED on this SUBJECT. TO UPDATE, I WROTE UNDER ANONYMOUS BLOCK.

    Number of Tables: TEMP_WED_TO_MONDAY is 46,921,912 and count of total of the table is 48052365

    Anonymous block:

    DECLARE
       CURSOR UPDATE_TEMP_DATE
       IS
          SELECT A,
                 B,
                 C,
                 D,
                 E,
                 F,
                 G,
                 E - 2 NEW_E
            FROM TEMP_WED_TO_MOONDAY;
    
    
       TYPE UPDATE_TEMP_DATE_REC IS RECORD
       (
          A       VARCHAR2 (50 CHAR),
          B       VARCHAR2 (50 CHAR),
          C       VARCHAR2 (50 CHAR),
          D       VARCHAR2 (18 CHAR),
          E       DATE,
          F       NUMBER,
          G       VARCHAR2 (50 CHAR),
          NEW_E   DATE
       );
    
    
       TYPE UPDATE_TEMP_DATE_TBL_TYPE IS TABLE OF UPDATE_TEMP_DATE_REC;
    
    
       UPDATE_TEMP_DATE_TBL   UPDATE_TEMP_DATE_TBL_TYPE;
    BEGIN
       OPEN UPDATE_TEMP_DATE;
    
    
       LOOP
          FETCH UPDATE_TEMP_DATE
             BULK COLLECT INTO UPDATE_TEMP_DATE_TBL
             LIMIT 1000000;
    
    
          EXIT WHEN UPDATE_TEMP_DATE_TBL.COUNT = 0;
    
    
          FORALL I IN UPDATE_TEMP_DATE_TBL.FIRST .. UPDATE_TEMP_DATE_TBL.LAST
             UPDATE TEMP
                SET E = UPDATE_TEMP_DATE_TBL (I).NEW_E
              WHERE     A = UPDATE_TEMP_DATE_TBL (I).A
                    AND B = UPDATE_TEMP_DATE_TBL (I).B
                    AND C = UPDATE_TEMP_DATE_TBL (I).C
                    AND D = UPDATE_TEMP_DATE_TBL (I).D
                    AND E = UPDATE_TEMP_DATE_TBL (I).E
                    AND F = UPDATE_TEMP_DATE_TBL (I).F
                    AND G = UPDATE_TEMP_DATE_TBL (I).G;
    
    
          COMMIT;
       END LOOP;
    
    
       CLOSE UPDATE_TEMP_DATE;
    END;
    
    

    But for the past 6 hours, it only updated records 20,00,000(Twenty lakh) only. because this update in the table and is also part of the teaching primary key I think it takes time, but pointers to improve/acceleration of the update

    Explain the plan:

    update statement all_rows (Cost 4)
      3 update hr.temp 
        2   table access by index rowid table hr.temp (Cost 4, Bytes : 64 ,Cardinality 1)
          1    index range scan index hr.temp_wed_to_monday (Cost 3: Cardinality 1)
    

    Thank you guys, I would be grateful if someone provides the solution for the scenario, rather than highlight the design. Please understand someone designed to best with whatever the limits it has during this period. (and this isn't me).

  • Another user changed the row with a primary key oracle.jbo.Key]

    I see many discussions about this error, but still cannot understand the difficulty that I need in my scenario.

    I am an Oracle Developer and completely new to ADF, please bear with me.

    I use JDeveloper 11.1.1.9.0

    My scenario:

    Creates an object editable view (UVO) with sub selects in the query, which is from several db tables.

    Creating a table using the UVO

    When I try to update a field in the table, and then click the validate, I get the error message:

    Another user changed the row with a primary key oracle.jbo.Key]

    Can someone explain in what scenarios I see this error and how do I solve this problem?

    Try the viewObject execution after validation and reQueryOnCommit set to true

    For details see - binary: a reason more for "Houston-25014: another user has modified the line containing oracle.jbo.Key primary key '

    Ashish

  • How to update a record, if it is a composite key (primary key is based on two columns) in the OPS? page?

    Hello

    Actually I got to know this update of a record must be made when the primary key is based on two columns.

    Previously, I used SPEL for a column. It was working fine.

    But I came to know that regardless of the folder I try to update, it was the update page is coming up with the first combination of the record.

    As if RC 131

    RC 124

    RC 125 are the records.

    If I click on update of RC 124 also, the update page is coming up with RC 131 values as it is the first.

    So I understand that the SPEL should be based on two parameters, because it is a composite key.

    How to do?

    Please let me know if you don't understand the problem.

    Thank you.

    Wow!

    I got it.

    Thank you brothers, always a hope that you could help me

  • update of a primary key column

    Hello

    I have a problem I want to expose you for your opinion.

    In a table of the source, I have a primary key consisting of four columns (let's call them A, B, C and D).

    Columns D must be updated with a different value (a Mappin with another table)

    My ODI interface, I set the update keys a, B, C, but of course, it does not work because there is violation of the primary key

    I thought, the first value of D in a new column (D_OLD) and use as a 4th update key.

    What do you think?

    Please suggest me the right way to do it

    Thank you for your return

    Hello

    Maybe I did not understand your problem correctly, but you say that you want to update the value of col D what happens to the part b of your primary key. You cannot update the row using columns A, B and C, because they are not unique. Am I wrong? If this is the case, then how will you identify which line you want to update the value of col D for. Tell if you have 2 lines with the same value for columns A, B and C, and a different value of D so how do you know which line you want to update? If you have the answer to this question, then you should be able to update as well.

    Thank you

    Ajay

  • Add new ID/Primary Key column with custom ID generation

    I use Hibernate as ORM to interact with Oracle.

    This issue is no longer on the side of SQL to emulate the generator ID seqHiLo

    that we use to generate the primary key for tables, the column ID i.e.

    Now I want to add a new column to the ID of an already created table, and this table has data.

    I have a procedure to add the ID column in a table:

    For example:

    ALTER table TableName add (columnName NUMBER);

    Then create the sequence

    CREATE SEQUENCE SEQ_ID

    START WITH 1

    INCREMENT BY 1

    MAXVALUE 99999999

    MINVALUE 1

    NOCYCLE;

    and after that he use the UPDATE statement to insert some values into the column like this

    UPDATE tableName SET columnName is seq_test_id. NEXTVAL

    Here I intend to use hibernate_sequence, to be in harmony with the hibernation of generation mode the ID's

    The question is:

    UPDATE tableName SET columnName = hibernate_sequence. NEXTVAL, generates the ID in the order.

    However, I need identifiers according to the algorithm of seqHiLo.

    Is there a way to do this in pure SQL?

    In short, can we have a personalized way to generate IDS to use in the new column, rather than a sequential,

    as stated above?

    If you update every row of a session, it won't make any difference if you select from a sequence and use this value immediately (as in your example) or if you go through the algorithm of HiLo: be it you will end up with sequentially numbered lines without leaving space. Then after the update block of existing lines, you will need to create the sequence to be used by your Hibernate application with an initial value of your current value divided by the low value.

    If you really want to implement the algorithm of HiLo for the bulk loading, you can of course do so. But it is not necessary: the effect will be the same.

  • Update a primary key of type char data

    Hello
    Not a guy to oracle technology. but am forced to work on a query that is a basic requirement.

    I have a table that has a composite primary key values (6 columns).
    Of these, I've updated 1 specific column, which is a char data type.

    I tested after writing my logic as a query, threw it [the Unique constraint violated schema.tablename];

    So I gave it a query simple base to test it yet, still get the same error.

    Query such as:

    Update table_name set Column1 = "100000" where column2 = 'BOMBAY '; (Column1 is the primary key of type char)

    Even if it did not work.
    Now a doubt arises, a column is a primary key of type Char can be modified? or is it not possible at all to do?

    Note: I made sure only am not updated with a duplicate value;


    Thank you.

    Published by: 966353 on October 18, 2012 12:01

    While you never need to update a primary key (regardless of the type of data), it is possible to do. If you get an error ORA-00001 indicating that a unique constraint has been violated and the unique constraint that is violated is associated with the primary key of the table (I'm guessing that this is the case according to your description of the error), implying strongly that the update would result in duplicate rows. Your UPDATE statement updates more than 1 row? If so, how do you determine when the update is complete there will be no duplicate lines?

    Justin

Maybe you are looking for

  • Download

    Currently purchased new 6 s.  My list of purchased songs on the list, but impossible to download some of them. Need ideas on how to achieve this.

  • How can I determine which Intel SSD is compatible with my MacBook PRo mid-2012?

    I have a MacBook Pro 13 inch Mid 2012 (not retina) and I need to upgrade my hard drive to an SSD. I've seen several like Intel s 540 and 750 series and a Crucial MX SSD. However, I am trying to identify the one which would be compatible and the best

  • How can I change the default search engine in the address bar?

    Beta toolbar AVG changed the search engine used when I type in the address bar of Yahoo search. I uninstalled AVG completely toolbar beta, but I can't seem to find out how to change the search back to Google search engine.

  • all the success with XQuartz?

    I use my MacbookPro (retina - 2012, running OS El Capitan x 10.11.4) 13 "update the firmware for a sheet of material, but the seller of (non-Apple) hardware does not support El Capitan. The seller offers I have install XQuartz 2.7.8 to complete the u

  • Re: Portege 500 Sync and Fingerprint Software on Vista

    HI - have recently resolved the synchronization failure by removing the true Suite Access Manager (finger printing software). Vista invites you to reinstall the software when you restart, which I did download from the Toshiba... and we're back to the