How to modify primary key column?

I want to modify one primary key column, But TT reported error.
How do I modify primary key column? Thanks first.

In TimesTen, the values in primary key columns cannot be updated (except for the trivial case where you update the value to the same value as it currently has). If you want to change the values stored in primary key columns the application must insert a new row with the new key values (and of course values for the other columns) and then delete the old row.
Chris

Similar Messages

  • How to know primary key column name form a table name in sql query

    Suppose I only know the table name. How to get its primary key column name from the table name?
    Thanks

    Views don't have primary keys though their underlying tables might. You'd need to pick apart the view to determine where it's columns are coming from.
    You can select the text of the view in question from user_views.

  • How to update primary key column

    Hi,
    Can you suggest me best workaround/algorithm for below task:
    (Oracle 10g, Solaris OS.)
    Situation:
    Table P has primary key column "Code", child tables F1, F2, ..., F15 reference with foreign key column "P_Code" column "P.Code", and we don't know which of the child tables has data for particular "P.Code" value.
    Task:
    Change "P.Code" value from 100 to 200. So that result would be that record P[Code = 100] should be updated as:
    update P set
    Code = 200
    where Code = 100;And child tables column "P_Code" should be updated as:
    update F1, F2, .., F15 set
    P_code = 200
    where P_code = 100;The best solution would be that one very easily can repeat that task.
    Edited by: CharlesRoos on 28.12.2010 12:10

    If you are looking for reusable and repetitive solution, then may be...
    SQL> CREATE TABLE p (p_code NUMBER PRIMARY KEY);
    Table created.
    SQL> INSERT INTO p VALUES(100);
    1 row created.
    SQL> INSERT INTO p VALUES(300);
    1 row created.
    SQL> INSERT INTO p VALUES(500);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> CREATE TABLE F1 (p_code NUMBER REFERENCES p(p_code));
    Table created.
    SQL> CREATE TABLE F2 (p_code NUMBER REFERENCES p(p_code));
    Table created.
    SQL> CREATE TABLE F3 (p_code NUMBER REFERENCES p(p_code));
    Table created.
    SQL> INSERT INTO F1 VALUES(100);
    1 row created.
    SQL> INSERT INTO F3 VALUES(100);
    1 row created.
    SQL> INSERT INTO F2 VALUES(500);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> CREATE OR REPLACE PROCEDURE update_child_parent(pi_p_code_old NUMBER,
      2                                                  pi_p_code_new NUMBER) IS
      3    CURSOR table_to_update IS
      4      SELECT table_name,
      5             to_number(extractvalue(xmltype(DBMS_XMLGEN.getxml('SELECT count(*) c FROM ' ||
      6                                                               table_name ||
      7                                                               ' WHERE p_code=' ||
      8                                                               pi_p_code_old)),
      9                                    '/ROWSET/ROW/C')) cnt
    10        FROM user_tables
    11       WHERE table_name IN ('F1', 'F2', 'F3');
    12 
    13  BEGIN
    14    EXECUTE IMMEDIATE 'ALTER TABLE p DISABLE PRIMARY KEY CASCADE';
    15    UPDATE p SET p_code = pi_p_code_new WHERE p_code = pi_p_code_old;
    16    FOR i IN table_to_update LOOP
    17      IF i.cnt > 0 THEN
    18        EXECUTE IMMEDIATE 'UPDATE ' || i.table_name || ' SET p_code=' ||
    19                          pi_p_code_new || ' WHERE p_code=' || pi_p_code_old;
    20      END IF;
    21    END LOOP;
    22    EXECUTE IMMEDIATE 'ALTER TABLE p ENABLE VALIDATE PRIMARY KEY';
    23  END update_child_parent;
    24  /
    Procedure created.
    SQL> EXECUTE update_child_parent(100,200);
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM p;
        P_CODE
           200
           300
           500
    SQL> SELECT * FROM F1;
        P_CODE
           200
    SQL> SELECT * FROM F2;
        P_CODE
           500
    SQL> SELECT * FROM F3;
        P_CODE
           200
    SQL> INSERT INTO p VALUES(300);
    INSERT INTO p VALUES(300)
    ERROR at line 1:
    ORA-00001: unique constraint (HR.SYS_C005931) violated
    SQL> EXECUTE update_child_parent(500,900);
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM p;
        P_CODE
           200
           300
           900
    SQL>  SELECT * FROM F2;
        P_CODE
           900
    SQL>

  • How can I modify a column to a primary key column

    Hi,
    I've created a table with no primary key. How I can set the primary key column now? The datatype of the "primary key" column is Raw(35).
    Thanks,
    Mike

    Mike,
    Issue the following command:
    ALTER TABLE table_name
    ADD CONSTRAINT constraint_name PRIMARY KEY(column_name);
    NOTE: If you want to place the primary key data in a separate tablespace, then you can add the key word USING INDEX TABLESPACE after the column_name.
    Regards,
    John

  • How to change (decrease) primary key column length?

    Hi all,
    I have plenty of data in the table and I need to decrease the primary key column from CHAR(17) to CHAR(13).
    I try to use:
    ALTER TABLE xx MODIFY (prmy_key (13));
    but Oracle give:
    ERROR at line 1:
    ORA-01441: column to be modified must be empty to decrease column length
    Can anyone give me advice on what is the best way to decrease column length? Thanks in advance for your help.

    To add to the above, I have done a simple test in the lines that I was suggesting the solution for this problem,
       CREATE TABLE testA
       (pk_col   varchar2(20), jd date, constraint pk1 PRIMARY KEY(pk_col));
       --Insert data into testA
       create table testB as select * from testA;
       TRUNCATE table testA;
       ALTER TABLE testA modify(pk_col VARCHAR2(10));   
       INSERT INTO testA SELECT substr(pk_col, 1, 10), jd from testB;
       DROP TABLE testB;
       Select constraint_name, constraint_type, status from all_constraints
       Where table_name = 'TESTA';
       CONSTRAINT_NAME                C STATUS
       PK1                            P ENABLEDAlter command is successful as the table is empty. TRUNCATE flushes the data and resets the high water mark keeping all the constraints. If we safely want to use the TRUNCATE as far as storage issues are concerned,
    TRUNCATE table table_name reuse storage;
    I think, this would accoplish what has been asked.
    Let me know,
    SriDHAR

  • CDG-01141 ERROR: Module Component Table Usage ...  Table usage ... requires primary key column for referential integrity

    For some strange reason when I modified a form, (commented out some code in a when-window-activated trigger) I now get the following error.
    CDG-01141 ERROR: Module Component Table Usage GR1130A.CUSTOMER.GR_CUSTOMER.GC: Table usage GR_CUSTOMER requires primary key column for referential integrity
    I am sure this is not related to my change, but do not know what may have caused this or how to fix it.
    Anyone seen this error before? been able to fix it?
    Thanks!
    Windows 7
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0
    Designer Version 6.5.95.4.8

    You know that Developer/Designer 6i is not certified for Windows 7, right? Also, your version is not the latest one, so you can try to install the latest patch set first.
    >Table usage GR_CUSTOMER requires primary key column for referential integrity
    Check if there is a PK in the table definition (not in the database, but in Designer).

  • How to find primary key?

    I am trying to impliment a load using JDBC wherein I read the table name, some column names, and associated
    column data from a file (delimited or XML). The primary key columns are in the column names / data BUT I don't
    know which columns they are (based on the file I'm reading). Even if this information was in the file, I would need to
    verify the table I'm targeting does in fact have that primary key. I can insert the records fine BUT to use the records
    to update I need to determine from the database which are the primary key columns (by name).
    Essentially I'm trying to do the following:
    insert record into table
    if fails because of duplicate primary key
    determine the primary key of the current table
    retrieve the already existing record
    modify the retrieved record using my load data
    update the already existing record in the database
    My primary concern, now, is Oracle although I'm hoping to impliment this in as portable a fashion as possible.
    Thanks.
    R.Parr
    TemporalArts
    608.833.4578
    null

    You can check the DBA_CONSTRAINTS view for that: http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_1037.htm#i1576022

  • Partition key on non primary key column

    I have scenario where the table has defined non primary key column as "partition key".
    I was wondering how it will affect the purge/archive process if the index and table are using different column (they are not aligned)?
    What should be the solution to this scenario?
    Can I use the non primary key column as partition key? Is this affect purging/archiving or switching -IN or OUT partitions?
    Here is the article which Im following but didn't get the precise answer:
    "When the indexes and the table use the same partitioning function and columns in the same order, the table and index
    are aligned." 
    https://msdn.microsoft.com/en-US/library/ms345146%28v=SQL.90%29.aspx?f=255&MSPPError=-2147217396#sql2k5parti_topic9
    Look at "Index
    Partitioning" and "Defining
    the Partitioning Key" section.
    ZK

    If it non aligned, you cannot do switching in or out.  to switch, you should have aligned partitons.
    Hope it Helps!!

  • How to create Primary key

    I want to insert HOSTID that has unique values in a new application in a primary key column in database.
    I am starting with h000000001
    and I want to go from that to h000000002
    and .... h0000000010 , 11, 12 etc etc.
    How do I do this?
    I did this:
    rs = stmt.executeQuery("select wlbmach_host_id from wlbmach order by wlbmach_host_id desc");
    // I am getting the greatest value eg: h000999999
    if (rs.next())
    getHostID = (String)rs.getString("wlbmach_host_id");
    //Get the h0009999999
    getStringNumber = getHostID.substring(1,10);
    //This gives me 9999999
    try
    {getNum = Integer.parseInt(getStringNumber);
    //change number to integer so I can add 1 to it
    getNum=getNum+1;
    getStringNumber=Integer.toString(getNum);//make that a string
    getHostID="h"+getNum;//add h to it
    }//try
    catch(Exception e)
    {System.out.println("NumberFormatException might have occured");%>
    else
         System.out.println("Assigning first HostID");
         getHostID = "h00000001";
    System.out.println("HostID is "+getHostID);
    But gives Exception:String index out of range: 10.. My column can take 10 varchar ??
    Can someone help .. Is this the right way to do it ?
    Is there a better way to generate primay keys?

    Why are you making life difficult??? Why not use the SEQUENCE object (if you are using Oracle)? You can retrieve next value by "Select sequencename.nextval from dual" as the query...you will get your number. Also, when two requests are made at the same time, Oracle takes care of this problem for you...you do not need to synchronize the method in JAVA. Do some research in this...I think you will like it.

  • Knowing the primary key columns of the given table

    Hi,
    How can I get the primary key columns of the given table?
    Regards,
    Sachin R.K.

    You can find the constraint_name from all_constraints/user_constraints for constraint_type = 'P' (which is the primary key constraint).
    And then see which columns are in for the constriant_name
    in all_cons_columns/user_cons_columns view.
    Below is the example
    select acc.column_name from
    all_cons_columns acc, all_constraints ac
    where acc.constraint_name = ac.constraint_name
    and acc.table_name = 'DEPT' AND acc.owner = 'SCOTT'
    and ac.constraint_type = 'P'
    Hope this helps
    Srinivasa Medam

  • Add another Primary key column problem

    Hi all
    I do not Add primary key in existing table .how it possiable
    say I have Existing Table
    EMPNO NUMBER(4), primary key
    ENAME VARCHAR2(10 BYTE),
    JOB VARCHAR2(9 BYTE),
    EMPSLNO VARCHAR2(10 BYTE)
    Now Add another Primary key column(EMPSLNO)
    my coding this
    ALTER TABLE EMP_TEST ADD (
    CONSTRAINT PK_EMP_TEST PRIMARY KEY (EMPSLNO))
    but error message
    Error on line 0
    ALTER TABLE EMP_TEST ADD (
    CONSTRAINT PK_EMP_TEST PRIMARY KEY (EMPSLNO))
    ORA-02260: table can have only one primary key

    ..Or, too much few information, wild guess, (composite index)
    Do this :
    ALTER TABLE <your_table> ADD (
         CONSTRAINT PK_mycode PRIMARY KEY (head_code,item_code )
              USING INDEX TABLESPACE tbls_index;

  • Issue with getting sequance number from db in EO for a primary key column

    Hello Experts,
    we are working on ADf 11.1.1.2.
    we are facing issue with sequence number in our UAT instance.
    dev instance and sit instances did not gave any issues.
    We have one EO in that for one attribute we have given the value as
    new oracle.jbo.server.SequenceImpl("XXOZF_QA_CODE_S", object.getDBTransaction())).getSequenceNumber()
    in order to get the primary key column value from db sequance .
    <TransientExpression><![CDATA[(
    new oracle.jbo.server.SequenceImpl("XXOZF_QA_CODE_S", object.getDBTransaction())).getSequenceNumber()
    ]]></TransientExpression>
    now the issue is "I have incremented the sequence number through SQL plus from 10 to 20. And created a record on a VO which is based on above EO.
    But the sequence iam getting is 11 instead of 21."
    This is happening only in our uat instance all other instances are working fine.
    Can any one tell us how this frame work is still pointing tho the old sequnce number.
    regards
    Gayaz

    Also make sure that your sequence has NOCYCLE option.
    some thing like this:
    CREATE SEQUENCE test_seq
    START WITH 1
    INCREMENT BY 1
    NOCACHE
    NOCYCLE;

  • Missing entries in primary key column

    I want to find out the missing entries in column which is primary key column. Please give me the query.
    Thanks

    I want to find out the missing entries in column which is primary key columnPlease eleborate this a little, If you talking about null values hosted by primray key column, tell me, how's it possible?
    hare krishna
    Alok

  • Missing primary key column in created form?

    Please help. I am a newbie in apex.
    When i create form and view it later I am missing primary key column.
    HOw to make it show?
    Thanks in advance.

    Hi,
    While creating the form based on a table/view, what have you chosen to populate the primary key value? Existing Triggers or Existing Sequences or Custom PL/SQL function?
    Can you check for the Get PK pl/sql process in the page processing region of the related form page? If that function is missing then do the following steps to create the same,
    Step 1 : Create a new pl/sql process.
    Step 2 : Choose the Process Point as, On Submit After Computations and Validations.
    Step 3 : Write the following block,
    declare
      function get_pk return varchar2
      is
      begin
        for c1 in (select TEST_SEQ.nextval next_val
                   from dual) -- Create a new sequence for your requirement.
        loop
            return c1.next_val;
        end loop;
      end;
    begin
      :P3_TEST := get_pk;  -- Change the item name for your page.
    end;After doing all the above, try executing the page.
    Regards,
    Sakthi.

  • Selection criteria based on non-primary key columns in Custom-SQL

    Hi all,
    Could anybody please tell me how to perform a search using non-primary key columns, The query is written in Workbench under Custom Sql --> Read Object. The Query goes something like this
    select * from Employee where firstName like #name
    where firstName is a Non-primary key column.
    The Java Code goes like this
    Employee empm = new Employee();
    empm.setFirstName("John");
    Employee employees = (Employee) session.readObject(empm);
    This does not fetch me any values . I dont want the queries to be written in any java class. Is there Any other way to do it ??

    Hi all,
    Could anybody please tell me how to perform a
    search using non-primary key columns, The query is
    written in Workbench under Custom Sql --> Read
    Object. The Query goes something like this
    select * from Employee where firstName like #name
    where firstName is a Non-primary key column.
    The Java Code goes like this
    Employee empm = new Employee();
    empm.setFirstName("John");
    Employee employees = (Employee)
    session.readObject(empm);
    This does not fetch me any values . I dont want the
    queries to be written in any java class. Is there Any
    other way to do it ??I dont think you have set it up the right way to do what you want to do. You need to click on "Queries" on the Employee Descriptor and then Named Queries and then give a name for a named query and then choose ReadObjectQuery under type and then choose SQL under Format. Enter the custom SQL and then export the project xml file.
    Then in your application logic you have to call this named query the usual way.
    Employee employee = (Employee)session.executeQuery("findEmployeeByName,Employee.class,args);
    where args is a vector containing the name of the Employee.

Maybe you are looking for

  • Creating a new domain using WLST

    Hi, I am trying to write a WLST script to create a new domain without using an existing template. (Similar to the first option of "Generate a domain configured automatically to support the following BEA products" option when using the domain configur

  • Free sample sales - Control for Total Value

    Dear all, In our sales free process we configured a condition type Z100 Net value and condition record maintained with Key Customer / Material / Plant Higher authority is maintaining teh condition reocrd for one day. 10000/ Fg123456 / h210 - 100 % 12

  • Floppy Disk Trouble

    I can't seem to get my floppy disk to work correctly.  The light seems to stay on.  I've tried putting a disk in slowly, no force, and the light still stays on...  I tried going to my computer and clicking on drive A and waiting till it asked to inse

  • 2 dvds inserted into drive. i can't get them out! any ideas?

    My daughter inserted 2 dvds into the drive and the computer is trying to eject them, but they are stuck! any suggestions? can't find any advice on the apple website. thanks!

  • CS5, Windows 7 and the 'OPEN WITH' command fails

    I am having an 'issue' with the OPEN WITH command under Windows 7. I am running Windows 7 Home Premium (fully updated) edition and my system meets all of the advertised Adobe requirements. If I open Photoshop CS5 (64-bit); it will work OK and as expe