Primary Key modification

Hello,
I have a table with a primary key. There is an implicit index that is created with primary key - now I wish to alter this primary key so that I can use an another existing non-unique index (or by creating a new unique index). is there a way to achieve this? there are a lot of referentials associated with this primary key; hence I do not want to drop this primary key and re-create one.
Thanks,
Onkar

Parent Table -
+
CREATE TABLE TEST_PARENT_1
PARENT_ID VARCHAR2(2 BYTE),
PARENT_NAME VARCHAR2(20 BYTE),
PT_TIME TIMESTAMP(6)
TABLESPACE T1
LOGGING
PARTITION BY RANGE (PT_TIME)
PARTITION P1 VALUES LESS THAN (TIMESTAMP' 2012-04-01 00:00:00')
LOGGING
NOCOMPRESS
TABLESPACE T1,
PARTITION P2 VALUES LESS THAN (TIMESTAMP' 2012-05-01 00:00:00')
LOGGING
NOCOMPRESS
TABLESPACE T1
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;
CREATE UNIQUE INDEX PARENT_ID_1_PK ON TEST_PARENT_1
(PARENT_ID)
LOGGING
TABLESPACE T1
NOPARALLEL;
CREATE UNIQUE INDEX TEST_PARENT_IDX_1 ON TEST_PARENT_1
(PARENT_ID, PT_TIME)
TABLESPACE T1
LOGGING
LOCAL (
PARTITION P1
LOGGING
NOCOMPRESS
TABLESPACE T1,
PARTITION P2
LOGGING
NOCOMPRESS
TABLESPACE T2
NOPARALLEL;
ALTER TABLE TEST_PARENT_1 ADD (
CONSTRAINT PARENT_ID_1_PK
PRIMARY KEY
(PARENT_ID)
USING INDEX PARENT_ID_1_PK);
+
Child Table -
+
CREATE TABLE TEST_CHILD_1
PARENT_ID VARCHAR2(2 BYTE),
CHILD_ID VARCHAR2(2 BYTE),
CHILD_FIRST_NAME VARCHAR2(20 BYTE),
CHILD_LAST_NAME VARCHAR2(20 BYTE),
PT_TIME TIMESTAMP(6)
TABLESPACE T1
LOGGING
PARTITION BY RANGE (PT_TIME)
PARTITION P1 VALUES LESS THAN (TIMESTAMP' 2012-04-01 00:00:00')
LOGGING
NOCOMPRESS
TABLESPACE T1,
PARTITION P2 VALUES LESS THAN (TIMESTAMP' 2012-05-01 00:00:00')
LOGGING
NOCOMPRESS
TABLESPACE T1
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;
CREATE UNIQUE INDEX CHILD_ID_1_PK ON TEST_CHILD_1
(CHILD_ID)
LOGGING
TABLESPACE T1
NOPARALLEL;
ALTER TABLE TEST_CHILD_1 ADD (
CONSTRAINT CHILD_ID_1_PK
PRIMARY KEY
(CHILD_ID)
USING INDEX CHILD_ID_1_PK);
ALTER TABLE TEST_CHILD_1 ADD (
CONSTRAINT FK_TEST_CHILD_1
FOREIGN KEY (PARENT_ID)
REFERENCES TEST_PARENT_1 (PARENT_ID)
ON DELETE CASCADE);
+
I want to use TEST_PARENT_IDX_1 index for primary key in the TEST_PARENT_1 table. I hope this snippet helps.

Similar Messages

  • Composite Primary Key

    Hi,
    I have few tables which had primary key on one column A, I made it composite primary key by adding one more column B at 2nd position. I made this change in all the tables. When I ran few SQLs to check the performance I found that explain plan shows full table scan on few tables which was not showing eariler (before composite PK). The SQL has outer join between these tables on column A (1st position in composite PK index). Is there anything I need to look into?
    I'm using Oracle 10.2.0.5.0.
    Thanks

    Onkar Talekar wrote:
    I guess you are talking about the same table in this thread: [url:https://forums.oracle.com/forums/thread.jspa?threadID=2372871&start=0&tstart=0]Primary Key modification
    Yes. thats right.
    If it is the same post, could you post current structure of the table plus what is recommended in the FAQ to post for performance issues?
    Have you replaced your primary key from PARENT_ID to a composite primary key (PARENT_ID, PT_TIME)?
    What was the reason for that?
    Did you have any need to insert the same key (PARENT_ID) with different PT_TIME?
    What is the benefit you expected creating this index?
    What did you mean with "contention" that is happening on this primary key/index? Someone using the same primary key?
    How is the PARENT_ID generated?
    At a first look I did not see the need of replacing your primary key, as Tubby advised in your previous post. Adding a column to solve contention added additional trouble to you on performance side.
    Regards.
    Al.

  • Error while creating the Unique Index of the Primary Key of an Item

    Hi all,
    I have deployed a new item (CO_CONTRACTUNIT_PRODUCT) in my publication. The deploy appears to be successfull as the item can be seen in the repository through the Mobile Manager.
    The problem occurs when i sync my local DB to get the item offline. While synchronizing, the following error appears, both in the sync window and the log file ol_sync.log.
    "ERROR",POL-5130,"11/09/2010 11:43:52","table or view %s.%s not found:CO_CONTRACTUNIT_PRODUCT,CO_CONTRACTID,OD_PRODUCTID,CO_CONTRACTUNITID","DB_ROSHNI"
    However, the debug file gives this other error regarding this table.
    ALL_INDEX:CREATE UNIQUE INDEX "TPCO_CONTRACTUNIT_PRODUCT_PK" ON CO_CONTRACTUNIT_PRODUCT (CO_CONTRACTID,OD_PRODUCTID,CO_CONTRACTUNITID) -5130Error at C:\ADE\omeprod_ol103021\olite\db\build\win\ocapi\..\..\..\src\ocapi\allindexes.cpp line:329 rc:-5130
    Build date Mar 29 2010
    okErr=(table or view %s.%s not found)
    mess=(CO_CONTRACTUNIT_PRODUCT,CO_CONTRACTID,OD_PRODUCTID,CO_CONTRACTUNITID)
    AddLog(-5130 "ERROR",POL-5130,"11/09/2010 11:43:52","table or view %s.%s not found:CO_CONTRACTUNIT_PRODUCT,CO_CONTRACTID,OD_PRODUCTID,CO_CONTRACTUNITID","DB_ROSHNI")
    But the index that is being created and is giving the error is the index created automatically with the Primary Key of the table, and so nothing has been modified in that.
    The primary key of the table is created with the three columns that are part of the index that is returning the error.
    As I could not solve the error, I tried to drop and re-create the item in the repository, but no luck. As a last option, i tried to remove the item from the repository to be able to sync properly again (just like before creating the item), but the error still happens.
    Another weird point is that i have tried creating the item in another publication of another database (but with almost equal items), and the item could was downloaded to my local DB without any problem, which makes this problem still more bizarre.
    What can it be?
    Any help would be great!
    Roshni

    have you tried unistalling the client and reinstalling it?
    schema evolution changes are not always handled correctly please check thread:
    Modification of publication item into Mobile Server
    i quote from rekounas instructions:
    If you are just adding a field, you should only have to run the alter publication item API call.
    Here is an old note on schema evolution on different scenarios. The names for the APIs that they use are now deprecated. Use the ConsolidatorManager class and call the method alterPublicationItem("PUBLICATION_ITEM_NAME", "SELECT STMT") :
    A) Add column
    1. Upload all client data. Clients should not add new data until they are told by the administrator to sync again!!
    2. Stop Mobile Server listener
    3. Change the Oracle8i/9i database schema (add column)
    4. Create a Java program to call the Consolidator Admin API AlterPublicationItem()
    5. Start Mobile Server
    6. Execute a sync from the client
    7. The new column should be seen on the client. Use MSQL to check snapshot definitions.
    B) Drop column
    1. Upload all client data. Clients should not add new data until they are told by the administrator to sync again!!
    2. Stop Mobile Server listener
    3. Delete column of the base table in the Oracle database schema
    4. Create a Java program to call the Consolidator Admin API DropPublicationItem()
    5. Create a Java program to call the Consolidator Admin API CreatePublicationItem() and AddPublicationItem().
    6. Start Mobile Server
    7. Execute a sync from the client
    8. The new column should be seen on the cliet. Use MSQL to check snapshot definitions.
    C) Change column datatype
    Changing datatypes in a repliatated system is not an easy task. You have to follow certain procedures in order to make it to work. Use DropPublicationItem, CreatePublicationItem and AddPublicationItem methods from the Consolidator Admin API. You must stop/start Mobile Server listener to refresh the cache.
    1. Client syncs. Clients should not add new data until they are told by the administrator to sync again!!
    2. Stop Mobile Server listener
    3. Drop/create column (do not use conversion procudures) at the base table
    4. Call DropPublicationItem(). Check if the ErrorQueue and InQueue no longer exist.
    5. Call CreatePublicationItem() and AddPublicationItem(). Check if the ErrorQueue and InQueue reflect the new column datatype
    6. Start Mobile Server. This automatically resumes application
    7. Client executes sync. This should drop the old snapshot and recreate the new snapshot. Use MSQL to check
    snapshot definitions.
    D) Drop table
    1. Client syncs. Clients should not add new data until they are told by the administrator to sync again!!
    2. Stop Mobile Server listener
    3. Drop base table
    4. Call DropPublicationItem(). Check if the ErrorQueue and InQueue no longer exist.
    5. Start Mobile Server. This automatically resumes application
    6. Client executes sync. This should drop the old snapshot. Use MSQL to check snapshot definitions.
    E) Add table
    1. Client syncs. Clients should not add new data until they are told by the administrator to sync again!!
    2. Stop Mobile Server listener
    3. Add new base table
    4. Call CreatePublicationItem() and AddPublicationItem() method
    5. Start Mobile Server. This automatically resumes application
    6. Client executes sync. This should add the new snapshot. Use MSQL to check snapshot definitions.
    F) Changing Primary Keys
    Chaning PK is a severe operation which must be executed manually. A snapshot must be deleted and recreated to propagate the changes to the clients. This causes a full refresh on this snapshot.
    1. Client syncs. Clients should not add new data until they are told by the administrator to sync again!!
    2. Stop Mobile Server listener
    3. Drop the snapshot using DropPublicationItem() method o
    4. Alter the base table
    5. Call CreatePublicationItem()and AddPublicationItem() methods for the altered table
    6. Start Mobile Server. This automatically resumes application
    7. Client executes sync. The old snapshot will be replaced by the new snapstot using a full refresh. Use MSQL to check snapshot definitions.
    G) To Change a Table Weight =>
    Follow the procedure below to change the Table Weight parameter. The table weight is used by the Mobile Server/Synchronization to determin the sequence in which client records are applied to the Oracle database.
    1. Run MGP to apply any changes in the InQueue to the Oracle databse
    2. Change table weight using SetTemplateItemMetadata() method
    3. Add/change constraint on the the base table which reflects the change in table weight
    4. Synchronize
    gl m8

  • Define primary key in FormsGraph Bean

    Hi !
    I read that I need to declare a primary key for using MODIFY_ROW_DATA or REMOVE_DATA.
    The problem is that there is 4 columns in the primary key of my table.
    So, how can I declare this primary key in the FormsGraph Bean ?
    Thanks for your help.
    Sev

    Hi,
    because the BI Graph relational API doesn't support a 4th extra field for e.g. holding primary keys, the modify row data does a full object comparison, comparing - in your case the routine in localRelationalData.java compares the values of
    xxx
    v_week
    v_quantity
    with values found in the existing data object, which is held in memory. To be sure of what happens, please enable debugging on the Graph bean before performing the modification. The effect you see can have many reasons e.g. that the refresh of the screen doesn't work or that the implementation itself has a problem. The debug messages that get written to the JInitiator shows if there is a match found for the data you provided (message starts with "ModifyData(): ") . Also the output starting with "parseStringData()" is interesting.
    Note that the Java source code is shipped with the demos - just in case you want to have a look yourself
    Frank

  • Primary key and WHO columns on EO

    We are trying to create a EO based on a database view. We do not have primary key and standard OA WHO columns but the OA framework is forcing us the have these columns. How do we go about this issue? Any suggestion will be appreciated.

    Oracle Apps mandates that you should have the Audit columns in the Applications tables.
    So you must have the 5 columns defined.
    I have created new tables for my application and need to populate them whenever user creates or modifies any row
    Jdeveloper/BC4J handles direct updates/inserts through default EO implementation, it would insert/update/delete from the base table via the EO, what is your qeustion then ? do you want to know how to perform DMLs in OA or something else ?
    Thanks
    Tapash

  • CHILD form error FRM-30100: Block must have at least one primary key item.

    Hi friends,
    I have increased the DML array of the child block from 1 to 10, but it throws me error:
    FRM-30100: Block must have at least one primary key item.
    Block: CEC_ADJUSTMENT_RECON
    Form: CEC_ADJ
    FRM-30085: Unable to adjust form for output.
    How does a form know that the table does not have primary key? Is it referring to it?
    Thanks a lot                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    I dont understand why do you increase the DML array size..
    Because it says in the HELP
    Specifies the maximum array size for inserting, updating, and deleting records in the database at one time.
    A larger size reduces transaction processing time by reducing network traffic to the database, but requires more memory.  The optimal size is the number of records a user modifies in one transaction.
    The FRM-30100 comes not because of the above property..
    If your query data source type is other than TABLE, it is a must to set at least one database field's PRIMARY KEY ITEM PROPERTY in the block to be a YES.

  • Locking Down a Primary Key Value

    What is the best way to guarantee that a primary key field value cannot be changed? Should I use a trigger to prevent such attempts? If so, what would the trigger script look like? This is a problem because the primary key will be used as a foreign key in other tables, and its value should never change once set. Thanks in advance.
    Evan

    If foreign key constraints are in place, Oracle won't allow you to change a primary key in the parent table if there is a record in the child table that depends on that value.
    Depending on the application design, you may be able to do things such as not grant UPDATE privileges on the primary key column to the users.
    You could also write a trigger that would prevent modifications, though that would tend to be a bit of overkill. Something like
    CREATE OR REPLACE TRIGGER no_change_primary_key
      BEFORE UPDATE OF <<primary key column>> ON <<table>>
      FOR EACH ROW
    BEGIN
      RAISE_APPLICATION_ERROR( -20001, 'Dude.  You cannot change the primary key!' );
    END;
      1  CREATE OR REPLACE TRIGGER no_change_primary_key
      2    BEFORE UPDATE OF empno ON emp
      3    FOR EACH ROW
      4  BEGIN
      5    RAISE_APPLICATION_ERROR( -20001, 'Dude.  You cannot change the primary key!' );
      6* END;
    SCOTT @ HP92 Local> /
    Trigger created.
    SCOTT @ HP92 Local> update emp set empno = 1 + empno;
    update emp set empno = 1 + empno
    ERROR at line 1:
    ORA-20001: Dude.  You cannot change the primary key!
    ORA-06512: at "SCOTT.NO_CHANGE_PRIMARY_KEY", line 2
    ORA-04088: error during execution of trigger 'SCOTT.NO_CHANGE_PRIMARY_KEY'Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Updateable columns with primary key

    Hi,
    I use HTML DB 2.0 and 10g R1.
    With HTML DB i would like create an application with 2 pages.
    The first page is an report from a table with 2 columns, the first column is datatype number(10) with primary key and the second column is varchar2(255).
    The report should looks like with an edit-icon for all rows and both columns with header.
    My problem is, the report has only 2 columns, not 3 columns and the edit-icon is together with the first table column, the header name is Edit.
    What can I do ?
    The second page should be a form linked from the first page for update, insert and delete rows. It's not possible to use a sequence on column with pk for new inserts.
    I don't know, which sample application has the same content or what I have to do.
    Who can help me ?

    Simply create an application "Report and Form" based on your table and modify it as follows:
    - On the report page, modify the query to include the PK column a second time (using an alias)... if this was based on the EMP table with EMPNO being the PK, the query then looks like this (modification bold):
    select
    "EMPNO",
    "EMPNO" as "EMPPLOYEE NUMBER",
    "ENAME",
    "JOB",
    "MGR",
    "HIREDATE",
    "SAL",
    "COMM",
    "DEPTNO"
    from "EMP"
    where
    instr(upper("ENAME"),upper(nvl(:P1_REPORT_SEARCH,"ENAME"))) > 0 or
    instr(upper("JOB"),upper(nvl(:P1_REPORT_SEARCH,"JOB"))) > 0
    - In the report attributes, move the added column to the desired position (I moved it directly next to the edit link).
    - On the Form page, just change the item holding your PK column from "hidden" to "Text field".
    You may take a look at http://htmldb.oracle.com/pls/otn/f?p=PK_VISIBLE:1 to verify this is what you're looking for.
    Edit: Oops - I just recognized I cannot update the EMPNO on page 2 since the automated row processing depends on an unchanged PK. However - normally it isn't a good idea to update a PK anyway (since it might be used as FK in some other table(s)).
    It is possible to create new records with manually adding the new PK, so if this is really all you need, then I would suggest you modify your edit page displaying the PK column read-only when editing an existing row and updatable when adding a new record (using 2 items with conditional display, based on the PK being NULL or NOT NULL).
    Holger
    Message was edited by:
    schweich

  • Primary key enable error

    hi,
    SQL> alter table SERVRECD4 enable constraint SERVRECD4_I0;
    alter table SERVRECD4 enable constraint SERVRECD4_I0
    ERROR at line 1:
    ORA-02437: cannot validate (MUSADMIN.SERVRECD4_I0) - primary key violated
    SQL> select constraint_name from user_constraints where status<>'ENABLED';
    CONSTRAINT_NAME
    SERVRECD4_I0
    I tried to check duplicates in this composite PK using following query:
    select FK_SERVRECD1NORAPA, FK_SERVRECD1FK_JO0, FK_SERVRECD1FK_JOB, FK_SERVRECD1ID from SERVRECD4 where row id NOT IN (select MIN(rowid) from SERVRECD4 group by FK_SERVRECD1NORAPA, FK_SERVRECD1FK_JO0, FK_SERVRECD1FK_JOB, FK_SERVRECD1ID);
    Result : No rows returned.
    Then i checked it and records aer same for below query as in table so it means NO duplicates then i don't seem to figure out why when trying to ENABLE constraint raises Above error.
    SQL> select count(min(rowid)) from SERVRECD4 group by FK_SERVRECD1NORAPA, FK_SERVRECD1FK_JO0, FK_SERVRECD1FK_JOB, FK_SERVRECD1ID;
    COUNT(MIN(ROWID))
    2729402
    SQL> select count(*) from SERVRECD4;
    COUNT(*)
    2729402
    Constraints Info:
    Name : SERVRECD4_I0
    Type : PRIMARY
    Table
    Columns : FK_SERVRECD1NORAPA,FK_SERVRECD1FK_JO0, FK_SERVRECD1FK_JOB, FK_SERVRECD1ID
    Disabled : YES
    Deferrable : NO
    Initially : NO
    Deferred : NO
    Validate : NO
    Its 10gR2 database on linux.
    thx

    A little modification in my early query ->
    select FK_SERVRECD1NORAPA,
           FK_SERVRECD1FK_JO0,
           FK_SERVRECD1FK_JOB,
           FK_SERVRECD1ID ,
           count(*)
    from SERVRECD4
    group by FK_SERVRECD1NORAPA,
           FK_SERVRECD1FK_JO0,
           FK_SERVRECD1FK_JOB,
           FK_SERVRECD1ID
    having count(trim(FK_SERVRECD1NORAPA)||
                 trim(FK_SERVRECD1FK_JO0)||
                 trim(FK_SERVRECD1FK_JOB)||
                 trim(K_SERVRECD1ID)) > 1;N.B.: Not Tested.....
    Regards.
    Satyaki De.

  • Modify the value of the primary key...

    Hi all,
    I have made a mistake in the design of the table......
    and it is too late to get it changed....
    I have set the wrong field as primary key...
    These fields (keys) need to be modify , since i ve set it as a key, when ever modify those fields using
    "MODIFY ZTABLE VALUE INT_TABLE . ", it create a new row into the table because i change the primary key value. Using "UPDATE ZTABLE ....." it doesnt works because the key's value has changed.
    Thank you very much friends...

    Hi Wong,
    If the primary key value does not exist then MODIFY statement creates a new record and if exists it modifies(updates)...
    So better change the Table Primary key and try to reapeat u r code...
    For changing the primary key just goto SE11 and just check the primary key which  u want to assign and uncheck the preivous one ( make sure the primary key on to first line) then save it and before activating goto<b> Utilities --> Database Utility --> activate and adjust database</b>
    Now u r table is activated without deleting previous data also...
    Regards,
    Sridhar

  • How to create one primary key for each vendor

    Hi all
    i am doing IDOC to jdbc scenario
    i am triggering idoc from R/3 and the data is going into DB table vendor through XI.
    structures are as follows:
    sender side: ZVendorIdoc (this is a customized IDOC , if i triger IDOC for multiple vendors then it triggers only 1 idoc with multiple segment )
    Receiver side:
    DT_testVendor
        Table
            tblVendor
                action UPDATE_INSERT
                access                     1:unbounded
                    cVendorName         1
                    cVendorCode        1
                    fromdate                1
                    todate                    1
                 Key1
                    cVendorName         1
    if i trigger idoc for multiple vendors ,for example vendor 2005,2006 and 2010 . then i can see that the only key comes from the very first field (2005) and the whole record for vendor 2005,2006 and 2010  goes into the table with this(2005) as a primary key
    now again if i send data for these three vendor 2005, 2006 , 2010, in which record for the vendor 2005 is same and for 2006 and 2010 are different than it takes 2005 as a primary key and it does not update the data in the table.
    my requirement is like this:   for each vendor there should be one unique key assigned.
                                              for above said example there should come three keys one for each vendor .
    could you please help me how to do this???????????

    Hi,
      In Mapping Make the statement is 0-unbounded.For each vendor create a statement.This will solve your problem.
    Regards,
    Prakasu.M

  • Error While Deploying A CMP Entity Bean With A Composite Primary Key

    Hello all,
    I have a problem deploying CMP Entity beans with composite primary keys. I have a CMP Entity Bean, which contains a composite primary key composed of two local stubs. If you know more about this please respond to my post on the EJB forum (subject: CMP Bean Local Stub as a Field of a Primary Key Class).
    In the mean time, can you please tell me what following error message means and how to resolve it? From what I understand it might be a problem with Sun ONE AS 7, but I would like to make sure it's not me doing something wrong.
    [05/Jan/2005:12:49:03] WARNING ( 1896):      Validation error in bean CustomerSubscription: The type of non-static field customer of the key class
    test.subscription.CustomerSubscriptionCMP_1530383317_JDOState$Oid must be primitive or must implement java.io.Serializable.
         Update the type of the key class field.
         Warning: All primary key columns in primary table CustomerSubscription of the bean corresponding to the generated class test.subscription.CustomerSubscriptionCMP_1530383317_JDOState must be mapped to key fields.
         Map the following primary key columns to key fields: CustomerSubscription.CustomerEmail,CustomerSubscription.SubscriptionType. If you already have fields mapped to these columns, verify that they are key fields.Is it enough that a primary key class be serializable or all fields have to implement Serializable or be a primitive?
    Please let me know if you need more information to answer my question.
    Thanks.
    Nikola

    Hi Nikola,
    There are several problems with your CMP bean.
    1. Fields of a Primary Key Class must be a subset of CMP fields, so yes, they must be either a primitive or a Serializable type.
    2. Sun Application Server does not support Primary Key fields of an arbitrary Serializable type (i.e. those that will be stored
    as BLOB in the database), but only primitives, Java wrappers, String, and Date/Time types.
    Do you try to use stubs instead of relationships or for some other reason?
    If it's the former - look at the CMR fields.
    If it's the latter, I suggest to store these fields as regular CMP fields and use some other value as the PK. If you prefer that
    the CMP container generates the PK values, use the Unknown
    PrimaryKey feature.
    Regards,
    -marina

  • Logical standby and Primary keys

    Hi All,
    Why primary keys are essential for creating logical standby database? I have created a logical standby database on testing basis without having primary keys on most of the tables and it's working fine. I have not event put my main DB in force logging mode.

    I have not event put my main DB in force logging mode. This is because, redo log files or standby redo logfiles transforms into set of sql statements to update logical standby.
    Have you done any DML operations with nologging options and do you notice any errors in the alert.log? I just curious to know.
    But I wanted to know that, while system tablespace in hot backup mode,In the absence of both a primary key and a nonnull unique constraint/index, all columns of bounded size are logged as part of the UPDATE statement to identify the modified row. In other words, all columns except those with the following types are logged: LONG, LOB, LONG RAW, object type, and collections.
    Jaffar

  • Query to return list of all missing primary key ids from table T1

    I found this query online that returns a start and stop for a range of all missing primary key id values from table T1. However i want to rewrite this query to return a whole list of all the missing primary key ids and not a start and stop range. any help plz?
    select strt, stp
    from (select m.id + 1 as strt,
    (select min(id) - 1 from T1 x where x.id > m.id) as stp
    from T1 m left outer join T1 r on m.id = r.id - 1 where r.id is null)x where stp is not null

    with t as
              select  1 as id from dual union all
              select  2 as id from dual union all
              select  3 as id from dual union all
              select  5 as id from dual union all
              select  8 as id from dual union all
              select 10 as id from dual union all
              select 11 as id from dual union all
              select 20 as id from dual
    select  id_start + level missing_id
      from  (
             select  id id_start,
                     nullif(lead(id) over(order by id) - 1, id) id_end
               from  t
      start with id_end is not null
      connect by prior id_start = id_start
             and prior dbms_random.random is not null
             and level <= id_end - id_start
    MISSING_ID
             4
             6
             7
             9
            12
            13
            14
            15
            16
            17
            18
    MISSING_ID
            19
    12 rows selected.Or:
    with t as
              select  1 as id from dual union all
              select  2 as id from dual union all
              select  3 as id from dual union all
              select  5 as id from dual union all
              select  8 as id from dual union all
              select 10 as id from dual union all
              select 11 as id from dual union all
              select 20 as id from dual
    select  id_start + level - 1 missing_id
       from  (
              select  min(id) id_start,
                      max(id) id_end
                from  t
       connect by level <= id_end - id_start
    minus
    select  id
       from  t
    MISSING_ID
             4
             6
             7
             9
            12
            13
            14
            15
            16
            17
            18
    MISSING_ID
            19
    12 rows selected.SY.

  • Diff b/w primary key and unique key?

    what is the diff b/w primary key and unique key?

    Hi,
    With respect to functionality both are same.
    But in ABAP we only have Primary key for the Database tables declared in the Data Dictionary.
    Unique is generally is the term used with declaring key's for internal tables.
    Both primary and Unique keys can identify one record of a table.
    Regards,
    Sesh

Maybe you are looking for