You would design Tables without primary key?

If you were asked to design a schema, if you create a table (however irrelevant) without a primary key? For example, a 'unprofessional' table such as a logging of errors table that records exceptions thrown from stored procedures, create you this table without a primary key?

In a relational database you define und work with entities (tables) and you put in relationship to each other by joins. An entity must by definition always be identified by a unique key.
If you don't know what kind of unique key identifies your entries in the table, it is almost certain that working from home in your datamodel and table designs had not been made. Your database objects contain tables, and they must have a unique identifier. Often it is a primary key (PK) composed of several columns.

By definition a datamodel that contains the tables without primary keys is nomore a relational datamodel and one of the fundamental bases for the creation of a relational database is violated.

Frankly I do not understand why Oracle allows the tables without primary key. Another system such as SAP R/3 are more stringent. Primary keys are required in the SAP and believe, when starting, it is sometimes tedious to define the primary key structures, but it's the basis of designing together relational datamodel you will put in place. You now SAP is based often on a DB ORACLE layer. They could do it, and these "extend" their functionality. But they are smart guys in Walldorf, and they always refrained to do. It's a good guess to believe, they have a good reason for it.

Tables without primary key are NO relational tables, they are dungpiles. As Oracle needs priimary key itself in order to operate a relational database, ROWID have been defined. ROWID is the primary keys of the tables where the customer does not have a PK. But nice as ORACLE is, they strongly recommend not to use these ROWID in the application or database layer. ROWID is no identifier object that are stable in time and space (eg. two different databases in a distributed design oder a DEV and PROD-system).

Definition of PK implies certain rules for the programming of your application and your DML operations. Especially you often MERGE in a relational table instead of simply INSERT'ing piece in a dungpile.

When it later on with SELECT large datavolumes dataaccess, again the differences between well-defined joins (all based on the PK-relations) and joins non-unique keys will be the order of magnitude. Not only that, the latest degrades in performance much more quickly with the growth of result sets. When you start fumbling with no UNIQUE INDEXES, speed up performance in the operations of dungpiling you are already closer to hell than on a sunny day in the world of relational data.

Othmar Lippuner
SQL Reporting professional

Tags: Database

Similar Questions

  • Get 2 amounts of 2 columns of 2 tables without primary key

    I would like to get the sum of column A of table 1 and the sum of column D in table 2 without using the primary key.

    Because I can't link the two tables, the only corresponding value is not the primary key.

    TABLE 1

    COLUMN A.     COLUMN B |    COLUMN C

    PAID NUMBER DESCRIPTION

    15472 blabla1 S15-875

    18515S15-875 blabla1

    215526.52 blabla2 D17-517

    ...                               ...                           ...

    TABLE 2

    COLUMN D |     COLUMN E |    COLUMN F

    INVOICENUMBERDESCRIPTION

    185525 blabla1 S15-875

    158520 D17-517 blabla2

    8964D17-517

    blabla2

    I would like to see the number, the sum of which should be paid and what has been paid.

    But as you can see, you can pay in several times and there may be several invoices.

    There is therefore no link between two tables which is a primary key in both entities.

    No idea how I could get it?

    NUMBER |    DESCRIPTION |    BILL |     PAID

    S15-875 185525 33987 blabla1

    D17-517 blabla2 167484 215526.52

    The tables can be attached on «NUMBER», regardless of weather conditions, as a primary key is defined.

    sql> with table_1 as
      2    (         select 15472     as paid, 'S15-875' as "NUMBER", 'blabla1' as description from dual
      3    union all select 18515     as paid, 'S15-875' as "NUMBER", 'blabla1' as description from dual
      4    union all select 215526.52 as paid, 'D17-517' as "NUMBER", 'blabla2' as description from dual
      5    )
      6  , table_2 as
      7    (         select 185525    as invoice, 'S15-875' as "NUMBER", 'blabla1' as description from dual
      8    union all select 158520    as invoice, 'D17-517' as "NUMBER", 'blabla2' as description from dual
      9    union all select 8964      as invoice, 'D17-517' as "NUMBER", 'blabla2' as description from dual
     10    )
     11  select t1."NUMBER"     as "NUMBER"
     12  ,      t1.description  as description
     13  ,      ( select sum(t2.invoice) from table_2 t2 where t2."NUMBER" = t1."NUMBER" ) as invoice
     14  ,      sum(t1.paid)    as paid
     15  from   table_1 t1
     16  group by t1."NUMBER"
     17  ,        t1.description
     18  /
    
    NUMBER  DESCRIP    INVOICE       PAID
    ------- ------- ---------- ----------
    D17-517 blabla2     167484  215526.52
    S15-875 blabla1     185525      33987
    

    BTW: 'NUMBER' is a horrible name for a column. I strongly recommend to change something that is not a reserved word.

  • Potential problems for tables without primary keys and unique keys

    GoldenGate 11.2.1.0.3/Solaris 10
    DB: Oracle for Oracle (Source and target is 11.2.0.3)
    Topology: unidirectional


    In our one-way configuration GG, little of the tables being replicated is not a primary key or a Unique key.

    Last week when we have implemented GG for the test, we received warnings for these table below.
    GGSCI > add trandata WMHS_UD.crtn_dtl
    
    2013-01-12 11:34:33  WARNING OGG-00869  No unique key is defined for table 'CRTN_DTL'. All viable columns will be used to represent the key, but may not guarantee uniqueness.  KEYCOLS may be used to define the key.
    
    Logging of supplemental redo data enabled for table WMHS_UD.crtn_dtl.
    Replication seems to work very well for these tables.

    Googling, I think that there may be performance degradation when you replicate tables without PK or the United Kingdom.

    But are there other potential problems such as data of a certain kind not replicated to the lack of PK/UK?

    It really depends on the data.

    By default, GG is combining all columns as a virtual primary key but don't no conflict control by default. So when you can be sure that the record you insert into the table is unique, then it will work.
    BUT as soon as you insert the same record, which is already inserted, then you will encounter problems.

    Let me show what happens when you use an initial charge because it makes it easier to describe:
    We start at 10:00 the capture for a table. Now, you insert a record at 10:00 in the tables. When you now start an initial charge to 10.02, then check you have inserted in the database to 10.01 will be repeated two times. During the IPL as the initial charge is made to 10.02 and it includes data of 10.01 AND it will be replicated again through the process of capture/replicate.

  • Find tables without primary keys

    DB version: 10g Release 2

    We have several tables that do not have a primary key.

    I need to use USER_CONSTRAINTS view to find which of these tables that do not have a primary key.
    The following query will not work because there obviously returns all records where CONSTRAINT_TYPE! = « P »
    select table_name from user_Constraints WHERE constraint_type != 'P'
    I need to jump those table_names who have at least one occurrence of CONSTRAINT_TYPE = 'P '.

    Select table_name from user_tables where table_name
    not in
    (
    Select the table table_name from user_constraints where constraint_type = 'P '.
    )

  • 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).

  • Great advice table no primary key on the table.

    Dear gurus,

    Version: Oracle 11.2.0.3.0 running on Linux HAVE 6.

    I have a big standard table (400 million lines) which is a data dump, it was created with no primary key Yes crazy but it happens (very rare).  I have a few key columns indexed for the purpose of the motion, but I would like to know what are the options I have different indexing on a table to make it more efficient for running a query against it.

    Looking for simple opinion where further research.  I won't not give an example of the table structure - neither include the details, I'm looking for advice.

    Easy points for everyone.

    Thank you.

    Content

  • How to delete several lines in the details Table with PRIMARY KEY = ("VID", "LINEITEM")?

    Mr President

    My worm Jdev is 12.2.1.

    I have master tables / details.

    I have 2 lines for each PRIMARY KEY = ("VID", "LINEITEM") as below in the Details table.

    delete.png

    Please help how to get a button on a jsf page to remove these two lines at a time.

    Concerning

    So, in your app (data model) module, you have a master relationship / typical retail:

    And the relationship between them is based on some ViewLink

    Now go to the ViewLink, relationship, accessor.

    Take a look at the Destination accessor.

    Generate accessor object to check and give a name Acessor

    Then go to the master VO, Java and Include accessor, the class generate a display line:

    Go to the class view Java generated line, you'll find a method with the name of the accessor of the previous step, in the form of:

    public RowIterator getYourDetails...or_whaterever_IsAccessorName..() {
    }
    

    Now, in the same Java class, write the following Java method:

    public void removeDetails(){
      RowIterator details = getYourDetails...or_whaterever_IsAccessorName..(); // it is RowIterator over all details
      Row r = details.first();
      while (r != null) {
          r.remove();
          r = details.next();
      }
    }
    

    This method on the Cilent export line Interface:

    Finally, pass the data controls and drop this operation on the form as a button...

  • EJB without primary key

    Hi all

    Is im using jdeveloper 11g possible to use EJB to a table that does not have primary key contain?

    TNX,
    Azzaiel

    Hello

    Have a look here: http://www.jguru.com/faq/subtopic.jsp?topicID=126500

    You can set the PK of the entity

    Frank

  • addition of populated table's primary key column

    Hi all


    I am trying to add a column to a table that is already filled. The column to be added must be the primary key.
    As expected, oracle jumped to the top of the error (ORA-01758) of a column NOT NULL cannot be added, unless the table is empty.

    A possible way is to create a new temp table and then transfer all current data... rename the temporary table later.

    Is there another way to accomplish this?

    Thank you

    Hello

    As error suggested you cannot add a constraint not null on the new column to the table that is already filled. What else you can do next to you, you have a fairly simple and fast to create a temporary table and moving data?
    You can add the new column but null, update the column with values and alter the table of marking column as not null. But your idea of empty temporary table is simple and fast.

    CREATE TABLE my_objects
    AS
       SELECT 'my_new_column' my_new, owner
       FROM all_objects
       WHERE ROWNUM < 1;
    
    _Not Null_
    ALTER TABLE MY_OBJECTS
    MODIFY(MY_NEW  NOT NULL);
    
    _Primary key_
    ALTER TABLE MY_OBJECTS
     ADD CONSTRAINT MY_OBJECTS_PK
     PRIMARY KEY
     (MY_NEW);
    

    Concerning

  • What do you call a TABLE without constraints

    Is there any standard term to call a table that is to have no constraints.

    Called ordinary (heap-organized) or a Table without constraint.

    [http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/tables.htm]
    [http://download.oracle.com/docs/cd/B12037_01/server.101/b10743/data_int.htm]

    -André

  • Synthetic Primary Key (sequence number) vs natural primary key

    I wonder if the sequence number is better than the primary key. I found a few tables only use the sequence number, some tables use the primary key only, and a few tables use both. Can someone give me a clue, one that I use when you create a table? TX in advance.

    Published by: 1B, 3 may 2012 21:07

    I'm not sure I understand the question. I do not understand how it is either / or question.

    Virtually every table must have a primary key. You can either use a primary key natural (something in the data that is unique and immutable) or you would use a synthetic primary key which is filled from a sequence. I strongly suggest using synthetic primary keys generated from a sequence for your primary key.

    Justin

  • exp/imp with sequential primary key table.

    Hello

    I have a general question about EXP/IMP a table with primary key sequence. I need exp rows in this table of 11g DB and their imp to 9i DB. This table is the same on 11g and 9i. Table 11g is updated daily. I want to import lines which are the only new records to 9i to expedite the process. As this main table of the key is sequential, I intend to export with where table_key > N, N is the max of last importing table_key and then proceed to import on this dump file. Don't you see any problem doing it this way?
    Your expertise is greatly appreciated!

    Hello

    I have no problem at all.
    If you do not forget to use the 9i export tool, then you should be OK
    Also a full table export and import with ignore = Yes will ignore the records that violate the primary key and import only new records.
    However, it is not a very clean way to do it.

    Success!
    FJFranken

  • Primary key for the Table is

    Hello guys,.

    I have a question about the primary key in my fact table. In my fact table, the primary key is a combination of 3 different columns, 2 columns are primary keys in dimension tables 2 diff. Is it normal to have a primary key in a table of facts, which is a combination of 3 different columns. If yes then when us will be important to the OBI tool only 3 columns Phy layer appears as the PK. should I do the other 2 columns as the PK in the physical layer of the OBI tool or can I leave it as it is. Please let me know

    Thank you.

    I did as you asked me to. Can you let me also know what will happen if I do only a single key as PK and let them other 2 touch as it is. This will affect performance in > is it possible or will I get incorrect values?

    No, this will not affect anything, in any case explicitly will give you joined him again in the physical layer.
    But it is advisable to show the key columns in the physical layer of the RPD.

    Thank you
    Vino

  • DB sequence for the primary key

    Hello

    I have Table of key primary we use DB sequence in the database itself, for example if start a line (using sql client) DB without primary key sequence will do it for me, because of this trigger.

    (1) my doubt is if I generate A EO off this table I need to explicitly set db sequence for this attribute as this or no need to do this sequence bz DB does good for me!

    (new oracle.jbo.server.SequenceImpl("SEQ_NAME",adf.object.getDBTransaction())).getSequenceNumber()
    
    
    
    

    No, you use a db trigger all what you need to do is to define the type of the attribute DBSeqence. Then the framework will assign a negative value for the PK, which can and will be used as K until you commit the transaction. During this time the bed frame now generated correct sequence of relaxation and rights holders to PK all negative values of the line (and it's child row).

    Don't forget to check DBSequence attributes must have "Refresh on insert" together that it triggers the correct PK is read from the database after insertion.

    Do not use ' (new oracle.jbo.server.SequenceImpl ("SEQ_NAME", adf.object.getDBTransaction ()) .getSequenceNumber () ' attribute is the PK you use triggers to generate the sequence.

    Timo

  • Primary key cause problem in the meantime Partition Exchange

    DB: 11.2.0.2
    OPERATING SYSTEM: AIX 6.1

    I get the problem when exchanging data with range partitioned table. I have a partitioned table of interval and a regular intermediate table with data to be uploaded.
    Here are the steps that I did.
    SQL> CREATE TABLE DEMO_INTERVAL_DATA_LOAD (
                    ROLL_NUM        NUMBER(10),
                    CLASS_ID        NUMBER(2),
                    ADMISSION_DATE  DATE,
                    TOTAL_FEE       NUMBER(4),
                    COURSE_ID       NUMBER(4))
                    PARTITION BY RANGE (ADMISSION_DATE)
                    INTERVAL (NUMTOYMINTERVAL(3,'MONTH'))
                    ( PARTITION QUAT_1_2012 VALUES LESS THAN (TO_DATE('01-APR-2012','DD-MON-YYYY')),
                     PARTITION QUAT_2_2012 VALUES LESS THAN (TO_DATE('01-JUL-2012','DD-MON-YYYY')),
                     PARTITION QUAT_3_2012 VALUES LESS THAN (TO_DATE('01-OCT-2012','DD-MON-YYYY')),
                     PARTITION QUAT_4_2012 VALUES LESS THAN (TO_DATE('01-JAN-2013','DD-MON-YYYY')));
    
    Table created.
    
    SQL> ALTER TABLE DEMO_INTERVAL_DATA_LOAD ADD CONSTRAINT IDX_DEMO_ROLL PRIMARY KEY (ROLL_NUM);
    
    Table altered.
    
    SQL> SELECT TABLE_OWNER,
               TABLE_NAME,
               COMPOSITE,
               PARTITION_NAME,
           PARTITION_POSITION,
              TABLESPACE_NAME,
           LAST_ANALYZED
    FROM DBA_TAB_PARTITIONS
        WHERE TABLE_OWNER='SCOTT'
       AND TABLE_NAME='DEMO_INTERVAL_DATA_LOAD'
       ORDER BY PARTITION_POSITION;
    
    TABLE_OWNER                    TABLE_NAME                     COM PARTITION_NAME                 PARTITION_POSITION TABLESPACE_NAME                LAST_ANAL
    ------------------------------ ------------------------------ --- ------------------------------ ------------------ ------------------------------ ---------
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  QUAT_1_2012                                     1 USERS
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  QUAT_2_2012                                     2 USERS
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  QUAT_3_2012                                     3 USERS
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  QUAT_4_2012                                     4 USERS
    
    SQL> INSERT INTO DEMO_INTERVAL_DATA_LOAD VALUES (10,1,'12-MAR-2012',1000,90);
    
    1 row created.
    
    SQL> INSERT INTO DEMO_INTERVAL_DATA_LOAD VALUES (11,5,'01-JUN-2012',5000,80);
    
    1 row created.
    
    SQL> INSERT INTO DEMO_INTERVAL_DATA_LOAD VALUES (12,9,'12-SEP-2012',4000,20);
    
    1 row created.
    
    SQL> INSERT INTO DEMO_INTERVAL_DATA_LOAD VALUES (13,7,'29-DEC-2012',7000,10);
    
    1 row created.
    
    SQL> INSERT INTO DEMO_INTERVAL_DATA_LOAD VALUES (14,8,'21-JAN-2013',2000,50); ---- This row will create a new interval partition in table.
    
    1 row created.
    
    SQL> commit;
    
    SQL> SELECT TABLE_OWNER,
            TABLE_NAME,
            COMPOSITE,
            PARTITION_NAME,
            PARTITION_POSITION,
            TABLESPACE_NAME,
            LAST_ANALYZED
      FROM DBA_TAB_PARTITIONS
         WHERE TABLE_OWNER='SCOTT'
       AND TABLE_NAME='DEMO_INTERVAL_DATA_LOAD'
       ORDER BY PARTITION_POSITION;
    
    TABLE_OWNER                    TABLE_NAME                     COM PARTITION_NAME                 PARTITION_POSITION TABLESPACE_NAME                LAST_ANAL
    ------------------------------ ------------------------------ --- ------------------------------ ------------------ ------------------------------ ---------
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  QUAT_1_2012                                     1 USERS
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  QUAT_2_2012                                     2 USERS
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  QUAT_3_2012                                     3 USERS
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  QUAT_4_2012                                     4 USERS
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  SYS_P98                                         5 USERS   
    
    SYS_P98 partition is added to table automatically.
    
    SQL> CREATE TABLE DEMO_INTERVAL_DATA_LOAD_Y (
                    ROLL_NUM        NUMBER(10),
                    CLASS_ID        NUMBER(2),
                    ADMISSION_DATE  DATE,
                    TOTAL_FEE       NUMBER(4),
                    COURSE_ID       NUMBER(4)); 
    
    Table created.
    
    SQL> INSERT INTO DEMO_INTERVAL_DATA_LOAD_Y VALUES (30,3,'21-MAY-2013',2000,12);
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    
    Since, i need a partition in DEMO_INTERVAL_DATA_LOAD table, which can be used in partition exchange, so i create a new partition as below:
    
    
    SQL> LOCK TABLE DEMO_INTERVAL_DATA_LOAD PARTITION FOR (TO_DATE('01-APR-2013','DD-MON-YYYY')) IN SHARE MODE;
    
    Table(s) Locked.
    
    SQL> SELECT TABLE_OWNER,
               TABLE_NAME,
               COMPOSITE,
               PARTITION_NAME,
               PARTITION_POSITION,
               TABLESPACE_NAME,
               LAST_ANALYZED
    FROM DBA_TAB_PARTITIONS
        WHERE TABLE_OWNER='SCOTT'
       AND TABLE_NAME='DEMO_INTERVAL_DATA_LOAD'
       ORDER BY PARTITION_POSITION;
    
    TABLE_OWNER                    TABLE_NAME                     COM PARTITION_NAME                 PARTITION_POSITION TABLESPACE_NAME                LAST_ANAL
    ------------------------------ ------------------------------ --- ------------------------------ ------------------ ------------------------------ ---------
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  QUAT_1_2012                                     1 USERS
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  QUAT_2_2012                                     2 USERS
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  QUAT_3_2012                                     3 USERS
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  QUAT_4_2012                                     4 USERS
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  SYS_P98                                         5 USERS
    SCOTT                          DEMO_INTERVAL_DATA_LOAD        NO  SYS_P102                                        6 USERS
    
    SQL> ALTER TABLE DEMO_INTERVAL_DATA_LOAD
    EXCHANGE PARTITION SYS_P102
    WITH TABLE DEMO_INTERVAL_DATA_LOAD_Y
    INCLUDING INDEXES
    WITH VALIDATION;
    ALTER TABLE DEMO_INTERVAL_DATA_LOAD
    *
    ERROR at line 1:
    ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION
    Now, if I turn off and drop the primary key constraint, it works without any problem.
    SQL> alter table DEMO_INTERVAL_DATA_LOAD disable constraint IDX_DEMO_ROLL;
    
    Table altered.
    
    SQL> alter table DEMO_INTERVAL_DATA_LOAD drop constraint IDX_DEMO_ROLL;
    
    Table altered.
    
    SQL> ALTER TABLE DEMO_INTERVAL_DATA_LOAD
    EXCHANGE PARTITION SYS_P102
    WITH TABLE DEMO_INTERVAL_DATA_LOAD_Y
    INCLUDING INDEXES
    WITH VALIDATION; 
    
    Table altered.
    
    SQL> select * from DEMO_INTERVAL_DATA_LOAD partition (SYS_P102);
    
      ROLL_NUM   CLASS_ID ADMISSION  TOTAL_FEE  COURSE_ID
    ---------- ---------- --------- ---------- ----------
            30          3 21-MAY-13       2000         12
    
    SQL> select * from DEMO_INTERVAL_DATA_LOAD_Y;
    
    no rows selected
    Please suggest.

    First of all, thanks for posting the code that allows us to reproduce your test. It is essential for such problems.

    Because the primary key is global you will not be able to use

    INCLUDING INDEXES
    WITH VALIDATION;
    

    And you need to add the primary key to the temporary table

     ALTER TABLE DEMO_INTERVAL_DATA_LOAD_Y ADD CONSTRAINT IDX_DEMO_ROLL_Y PRIMARY KEY (ROLL_NUM);
    

    The Exchange will work. You must rebuild the primary key after the Exchange.

Maybe you are looking for