How to identify the primary key relationship, key and forien

Hello

I wanted to know for a given table, how to identify if there is no child table. I could get details of the constraint in ALL_CONSTRAINTS or DBA_CONSTRAINTS, but I will not be able to determine who his children tables.
If there is no other available table, it's possible to identify the parent and child tables so please please let me know.

I know that we can check through creation of Table (DDL) script, but I need to understand programmatically. Is sort available?

Thanks in advance.

Kind regards
SK

SK says:
Hello

I wanted to know for a given table, how to identify if there is no child table. I could get details of the constraint in ALL_CONSTRAINTS or DBA_CONSTRAINTS, but I will not be able to determine who his children tables.
If there is no other available table, it's possible to identify the parent and child tables so please please let me know.

I know that we can check through creation of Table (DDL) script, but I need to understand programmatically. Is sort available?

use

query using R_CONSTRAINT_NAME where CONSTRAINT_TYPE = 'R '.

SQL> desc user_constraints
 Name                            Null?    Type
 ----------------------------------------- -------- ----------------------------
 OWNER                                  VARCHAR2(30)
 CONSTRAINT_NAME                  NOT NULL VARCHAR2(30)
 CONSTRAINT_TYPE                        VARCHAR2(1)
 TABLE_NAME                       NOT NULL VARCHAR2(30)
 SEARCH_CONDITION                        LONG
 R_OWNER                             VARCHAR2(30)
 R_CONSTRAINT_NAME                        VARCHAR2(30)
 DELETE_RULE                             VARCHAR2(9)
 STATUS                              VARCHAR2(8)
 DEFERRABLE                             VARCHAR2(14)
 DEFERRED                             VARCHAR2(9)
 VALIDATED                             VARCHAR2(13)
 GENERATED                             VARCHAR2(14)
 BAD                                  VARCHAR2(3)
 RELY                                  VARCHAR2(4)
 LAST_CHANGE                             DATE
 INDEX_OWNER                             VARCHAR2(30)
 INDEX_NAME                             VARCHAR2(30)
 INVALID                             VARCHAR2(7)
 VIEW_RELATED                             VARCHAR2(14)

SQL> 

Tags: Database

Similar Questions

  • How to find the primary key columns in the tables in MS Access using SQL queries

    How to find the primary key columns in the tables in MS Access using SQL queries

    Hello

    This is the forum for Windows Vista programs related issues.

    For better assistance, please try instead the Forums in SQL Server .

    Thank you! Vincenzo Di Russo - Microsoft MVP Windows Internet Explorer, Windows Desktop Experience & security - since 2003. ~ ~ ~ My MVP profile: https://mvp.support.microsoft.com/profile/Vincenzo

  • How to generate the primary key element and move to another page?

    How to make the primary key value to another page in a table?

    Form on T_ITEMS 2.png

    Hello

    I am a beginner in the apex,

    Please, now I want to add the primary key to page 1 for item id in page 2...

    Notice:

    Before, I created (process of pl/sql in the rendering of page @ after the header section) to get the id of secuance.

    BEGIN
    :P17_ID := seq_t_items_id.NEXTVAL;
    END;
    
    
    

    primary key is generated for the element ID of page 1... BUT When I update 'page 1' I see error and solved when shut down my browser and open it again...

    Please help me to...

    1. Generate a primary key (article id @ page 1)... without refresh error. ?
    2. Pass him (item_id) on page 2

    Thank you all for...

    Sorry I'm beginner in apex,

    I don't know how Pass value of the item_id TO page 1 page 2 "in the form ID", turn to the first PHOTO... .
    Help me..

    Thank you

  • Problem with the primary key and indexes

    Hi all

    I'm looking a mess on one of our main tables.
    One of the developers here added an index on 3 columns in the table, thinking that it would speed up (not noticing that it had not a PK).

    Subsequently another developer has noticed there do not have a primary on key. So they added a touch of primry on the single column.

    The problem is that now the index created on 3 columns is bein used as the primary key index. As when the primary key is created a new index was not created.

    Is there anyway to get rid of this index/change it correct?

    This table is related to many many other tables, so when we tried to remove the index we could not due to the primary key and foreign key violations with other tables.

    Thanks in advance

    Oracle, as you found, is quite capable to use a column enformce multi index a single column primary key, as long as the pk column is the leader in the index. This should not cause performance issues for a search of PK and if the three indexed columns are often selected only may benefit from these types of queries.

    The only way to change that now, would be to drop all CF, drop and add the PK constraint and then add all the FK constraints. A long time and potentially dangerous (if you miss to add back of the FKs) endeavour. Certainly not worth the risk in my opinion.

    John

  • How to get the primary key of the node selected in af:tree

    Hi all

    I use JDeveloper 11.1.1.5.0.

    I want to get the primary key of the node selected in the af:tree element. I wrote the code below in SelectionListener:
        public void drzewkoRwaSelectionListener(SelectionEvent evt) {
            RichTree tree = (RichTree)evt.getSource();
            TreeModel model = (TreeModel)tree.getValue();
            RowKeySet rowKeySet = evt.getAddedSet();
            Object key = rowKeySet.iterator().next();
            
            model.setRowKey(key);
       
            System.out.println(rowKeySet);
            System.out.println(rowKeySet.size());
    The result looks like this:
    [[oracle.jbo.Key[5 ], oracle.jbo.Key[6 ], oracle.jbo.Key[12 ],oracle.jbo.Key[14 ]]]]
    1
    I need the values of the last 2 nodes:
    1: oracle.jbo.Key [14]
    2: oracle.jbo.Key [12]

    How can I get?

    Kind regards
    Wojtek.

    Hello

    Try this code:

    {} public void drzewkoRwaSelectionListener (evt SelectionEvent)
    RichTree tree = (RichTree) evt.getSource ();
    Model TreeModel (TreeModel) = tree.getValue ();
    RowKeySet rowKeySet = evt.getAddedSet ();
    Key of the object = rowKeySet.iterator () .next ();

    model.setRowKey (key);

    System.out.println (rowKeySet);
    System.out.println (rowKeySet.Size ());

    Object [] keys = rowKeySet.toArray ();
    List (list) = keys [0];
    Keys = list.toArray ();
    * //from the table keys, you can get according to the value you want using as: [2], [3] key *.

  • Shape of the apex - how to get the primary key value manually?

    Hello

    Whenever I create form by using wizard Apex, he asks me to specify the trigger/sequence/pl/sql function to fill the primary key value.

    However, if I want to specify primary key myself (ie. undetermined generated automatically), how I can clarify that?

    Thanx

    Hello

    You mean by yourself: by hand or by a pl/sql?

    If you say by trigger, the system does not take on what number is sent. If you can give it "manually".

    May I ask what is the reason for this?

    See you soon,.

    Arnaud

  • How to identify the primary Parent of a shared node?

    We have a property that is set to Local defined, inherit,

    Suppose the 'Color' property and currently is the behavior in DRM

    Parent A - blue

    Child 1 - blue (inherited from Parent)

    Child 2 - color blue (inherited from Parent)

    Child 3-color blue (inherited from Parent)

    Parent B - Red

    Child 3 ~ part 1 - red color (inherited from Parent B)

    Child 4-color red (inherited from Parent B)

    Children 5 - red color (inherited from Parent B)

    The customer has improved the requirement so that in the case of shared members 'color' is inherited from the primary parent like the example below.

    Parent B - Red

    Child 3 ~ action1 - blue (inherited from "Primary" Parent A)

    Child 4-color red (inherited from Parent B)

    Children 5 - red color (inherited from Parent B)

    I guess I'm going to need a new property like 'Primary colors' and I need to write a formula to calculate the color of base on the primary parent.  However, I do not know how to identify the "main Parent" a shared node we use version 11.1.1.2 N-Tier

    I'm looking for suggestions on how to calculate the value of the property you want.

    Any help will be greatly appreciated.

    Hello

    You can create a new property derived like u said and use instead of the property defined in your exports or anywhere where you have to refer to the color. The property set can be used just to take the user input.

    The new derived property should be a logic like that-

    If (PropValue (Core.SharedFlag_MDM),

    NodePropValue (PropValue (Core.PrimaryName_MDM), Custom.Colour)

    PropValue (Custom.Colour))

    Now, 11.1.1.2 I lost the memory of how the properties are referred to as - if they are just used with their names or namespaces is mentioned (Core. , custom.). You can change the formula accordingly to view properties

    Thus, if SharedFlag_MDM is True, then it will take the value of the property to its primary node, which is inherited from the primary parent and if the shared flag is False then it is just a varValeurProp on the node itself.

    I hope that answers you.

    Thank you

    Denzz

  • How to add the primary key for the table with the existing data?

    The table is already busy data. There was no primary key before, so for each column, there are some duplicate values.

    I want to add a new column, which should be of the integer data type and can automatically incremented, from 001. I tried with Oracle SQL Developer, but it says "ORA-01758: table must be empty to add mandatory (NOT NULL) column. How can I do? Thank you!

    Hello

    Look for the [ALTER TABLE | http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_3001.htm#sthref4803] command to find out how to add a column (step (1)) and a (step (3)) constraint to an existing table.

    For the step (2):

    CREATE SEQUENCE  employee_id_seq
    START WITH  1
    ;
    
    UPDATE  employee
    SET     id  = employee_id_seq.NEXTVAL;
    

    When you create a sequence, START WITH 1 is the default value, so that the line is not really necessary above... I've included just to show how you could start with any number you have chosen.

  • Database offline: how to configure the primary key storage options?

    I want to model a large database that has its primary keys in their own table space. I don't see primary key storage Options as I do for the index and the properties of the table. JDeveloper supports storage options capture for primary keys? I use JDeveloper 11 g 11.1.1.0.0.

    Published by: flszen on October 17, 2008 13:42

    Hello

    I entered an enhancement request for this

    Thank you very much

    Susan
    http://www.susanduncan.blogspot.com

  • How to disable the product key (and not via cmd or hacking)

    I used my new (but very slow) laptop on windows 7 starter edition, (walking at home preidum sorry for the bad grammar.) and I don't have 26 days (I think) until the expiry of my product key, if im wondering how do I deactivate the product key, I saw a command which can make your product key never expire im going to test on my virtual machine, in any case, bye!

    The standard method is to buy a permit.

  • How to connect the DELETE keys and BACKSPACE in the text box?

    Hi all

    So I know I can addEventListener (TextEvent.TEXT_INPUT, onTextInput) to capture any text entry events.

    How to capture when someone presses the DELETE key or back?

    I tried addEventListener (KeyboardEvent.KEY_DOWN, onKeyDown); with if(event.keyCode == Keyboard.BACKSPACE), but it triggers the event before the change is made to the text box.  I'd like capture the event return back after that the text box is updated.

    Any help appreciated.

    Also, does anyone know how to capture you cut / copy / paste events?

    Thank you

    Scott

    http://www.resultswebdesign.com.au/

    Hello

    Instead of listening for the KeyUp, then the event fires after change


    http://www.Adobe.com/2006/mxml"layout ="absolute">
       
            Import mx.controls.Alert;
               
    private void keyHandler(event:KeyboardEvent):void {}
    If (event.keyCode == Keyboard.BACKSPACE) {}
    Alert.Show ('detect')
    }
    }
    ]]>
       

       
       
       

    Hope that helps

    Andrew

  • How to refer to the primary key column of newly inserted rows of tabular form

    Hello

    I use APEX 4.2.0.00.27 with Oracle DB 11.2.0.3.0.

    I work with a tabular presentation wizard-created for insert and update a table using the integrated SRM process (sequence 10).  I'm trying to use a process of anonymous block of PL/SQL (sequence 30) to make another manipulation of table after the records were inserted or updated.  The manual process is associated with my tabular form and I use the variables of name of column binding in my program block.

    My (rsn_test) table has 3 columns: test_id (number), test_nbr (number), test_id2 (number).  Test_id column is identified as the primary key and the type of the source already exists a sequence rsn_test_seq.  Column test_id2 gets its default value 0 to a hidden page element.

    I would use my manual process for updating the value of the test_id2 column.  If it's 0 then I want to put the value of the column test_id.  If it is any other value, then it must remain at this value.  My logic works very well for an existing line, but I'm running into a problem with the newly added lines.  The new lines get inserted, but the test_id2 column remains the default value 0.  I can tell the debugger that the SRM process is triggered first and inserts the line, then my manual dealing with fires.  The problem seems to be that the connection variable: TEST_ID for the primary key column remains NULL after insertion.  I don't know how to get the value of the column test_id of my newly created line to use in my PL/SQL block to my update.

    Process of PL/SQL:

    DECLARE
    BEGIN
       :P7_SHOW := NULL;
       :P7_SHOW := NVL(:TEST_ID2,555) || ' and ' || NVL(:TEST_ID,787) || ' and ' || NVL(:TEST_NBR,9999);
       IF :TEST_ID2 = 0 AND :TEST_ID IS NOT NULL THEN
          UPDATE rsn_test
             SET test_id2 = :TEST_ID
           WHERE test_id = :TEST_ID;
       ELSE
          :TEST_ID2 := :TEST_ID2;
       END IF;
    END;
    
    

    Excerpt from the debugger:

    0.01625 0.00010 Processes - point: ON_SUBMIT_BEFORE_COMPUTATION
    0.01635 0.00008 Branch point: Before Computation
    0.01643 0.00003 Process point: AFTER_SUBMIT
    0.01646 0.00022 Tabs: Perform Branching for Tab Requests
    0.01668 0.00008 Branch point: Before Validation
    0.01676 0.00024 Validations:
    0.01700 0.00135 Perform basic and predefined validations:
    0.01835 0.00020 Perform custom validations:
    0.01855 0.00049 ...Validation "TEST_NBR must be numeric" - Type: ITEM_IS_NUMERIC
    0.01904 0.00007 ......Skip for row 1 because row hasn't changed
    0.01911 0.00016 ......Skip for row 2 because row hasn't changed
    0.01927 0.00012 ...Validation "TEST_ID2 must be numeric" - Type: ITEM_IS_NUMERIC
    0.01939 0.00007 ......Skip for row 1 because row hasn't changed
    0.01945 0.00018 ......Skip for row 2 because row hasn't changed
    0.01964 0.00005 Branch point: Before Processing
    0.01968 0.00004 Processes - point: AFTER_SUBMIT
    0.01972 0.00588 ...Process "ApplyMRU" - Type: MULTI_ROW_UPDATE
    0.02560 0.00154 ...Execute Statement: declare function x return varchar2 is begin begin for c1 in ( select "RSN_TEST_SEQ".nextval pk from sys.dual ) loop return c1.pk; end loop; end; return null; end; begin wwv_flow.g_value := x; end;
    0.02714 0.00140 ......Row 3: insert into "APPPCSRSN"."RSN_TEST" ( "TEST_ID", "TEST_NBR", "TEST_ID2") values ( :b1, :b2, :b3)
    0.02854 0.00011 ...Process "ApplyMRD" - Type: MULTI_ROW_DELETE
    0.02865 0.00004 ......Skip because condition or authorization evaluates to FALSE
    0.02869 0.00015 ...Process "Process Submit" - Type: PLSQL
    0.02884 0.00007 ......Skip for row 1 because row hasn't changed
    0.02891 0.00012 ......Skip for row 2 because row hasn't changed
    0.02903 0.00012 ......Process row 3
    0.02915 0.00429 ...Execute Statement: begin DECLARE BEGIN :P7_SHOW := NULL; :P7_SHOW := NVL(:TEST_ID2,555) || ' and ' || NVL(:TEST_ID,787) || ' and ' || NVL(:TEST_NBR,9999); IF :TEST_ID2 = 0 AND :TEST_ID IS NOT NULL THEN UPDATE rsn_test SET test_id2 = :TEST_NBR WHERE test_id = :TEST_ID; ELSE :TEST_ID2 := :TEST_ID2; END IF; END; end;
    0.03344 0.00013 ...Session State: Saved Item "P7_SHOW" New Value="0 and 787 and 1300"
    0.03356 0.00004 Branch point: After Processing
    0.03360 0.00048 ...Evaluating Branch: "AFTER_PROCESSING" Type: REDIRECT_URL Button: (No Button Pressed) Condition: (Unconditional)
    0.03407 0.00013 Redirecting to f?p=290:7:8717971109610:::::&success_msg=0%20row(s)%20updated%2C%201%20row(s)%20inserted.Success%2FEBD244168556408CBA714E3974918C09%2F
    0.03420 0.00012 Stop APEX Engine detected
    0.03432 0.00007 Stop APEX Engine detected
    0.03439 - Final commit
    
    

    Any suggestions?

    I have run tests on

    https://apex.Oracle.com/pls/apex/f?p=83488:1 demo/demo

    to see your problem.

    I have 2 solution for your problem.
    I add trial NOT tabular just usual block of PL/SQL

    BEGIN
    I'm IN (SELECT TEST_ID FROM RSN_TEST WHERE TEST_ID2 = 0)
    LOOP
          UPDATE RSN_TEST
             SET test_id2 = TEST_ID
           WHERE test_id = i.TEST_ID;
      END LOOP;
    END;

    and works very well, you can see in the sample.

    The other solution is to show new generated TEST_ID

    Adding a sequence as a default value for a column in a table field

    And to execute your procedure.

    I get how is with the good luck of time.

    By

  • Make required error appears only the primary key generated in prior Database Table insert trigger

    Dear all,

    I am a beginner in the ADF and am under Jdeveloper Studio Edition Version 12.2.1.0.0.


    I'm trying to insert a record, I created the trigger for insertion prior to get the primary key and set some other default values.


    On the page, I did read-only primary key column and false required.


    When I try to save - commit (Programmatic), I get errors for the required value. How can I stop this errors.


    Secondly, I also tried changing the agent to disabled on the attribute View object that raised the error below:


    < oracle.dfw.impl.incident.DiagnosticsDataExtractorImpl > < DiagnosticsDataExtractorImpl > < createADRIncident > < incident created 148 to key problem "DFW-99998 [oracle.jbo.PersistenceException] [oracle.jbo.server.RowReference.verifyPrimaryKeys] [Proposals]" >


    Hoping for help.


    Thanks and greetings


    Arif Khadas

    If the primary key values from DB sequence, you can follow this approach:

    Using the sequence of database in ADF - Souza Waslley Blog

    Oracle Fusion Middleware Technologies: ADF 11 G: generate the primary key sequence number

    Otherwise, instead of DB trigger, create the DB function that retrieves the value of the PK and call stored function in the overloaded method create() entity:

  • Question about when Oracle checks the primary keys

    I had data as follows in a table:
    id1  id2
    ---- ----
       1    2
       3    1
    Id1 is the primary key and what I wanted to do was
    update this_table set id1 = id2 where id2 in (1,2);
    I was afraid that if he updated the line with id2 = 1 first of all, it would fail on a unique key constraint. Rather than take this chance I did it with two separate update statements. But I wondered, would he worked with an update? Are primary keys verified at the level of the line or at the level of the statement?
    My level of Oracle 10 g (10.2.0.4.0) is

    Pretty easy to test:

    SQL> CREATE TABLE t (
      2     id1 NUMBER PRIMARY KEY,
      3     id2 NUMBER);
    
    Table created.
    
    SQL> INSERT /*+ APPEND */ INTO t
      2  SELECT id1, id2
      3  FROM (SELECT ROW_NUMBER() OVER(ORDER BY object_id) id1,
      4               ROW_NUMBER() OVER(ORDER BY object_id desc) id2
      6        FROM all_objects)
      7  ORDER BY DBMS_RANDOM.Value();
    
    18247 rows created.
    
    SQL> COMMIT;
    
    Commit complete.
    
    SQL> SELECT * FROM t;
    
           ID1        ID2
    ---------- ----------
          4498      13750
          3268      14980
         14947       3301
         12776       5472
          3796      14452
         10425       7823
          7182      11066
         14917       3331
              
    
    SQL> SELECT * FROM t ORDER BY id1;
    
           ID1        ID2
    ---------- ----------
             1      18247
             2      18246
             3      18245
             4      18244
             5      18243
             6      18242
             7      18241
             8      18240
             9      18239
            10      18238
              
    
    SQL> SELECT * FROM t ORDER BY id1 desc;
    
           ID1        ID2
    ---------- ----------
         18247          1
         18246          2
         18245          3
         18244          4
         18243          5
         18242          6
         18241          7
         18240          8
         18239          9
         18238         10
              
    
    SQL> update t set id1 = id2;
    
    18247 rows updated.
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 4143155445
    
    ---------------------------------------------------------------------------
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------
    |   0 | UPDATE STATEMENT   |      | 18247 |   463K|     5   (0)| 00:00:01 |
    |   1 |  UPDATE            | T    |       |       |            |          |
    |   2 |   TABLE ACCESS FULL| T    | 18247 |   463K|     5   (0)| 00:00:01 |
    ---------------------------------------------------------------------------
    

    within a single transaction, so that the end result does not violate the PK operation will succeed.

    SQL> rollback;
    
    Rollback complete.
    
    SQL> update t set id2 = 50 where id2 = 123;
    
    1 row updated.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> update t set id1 = id2;
    update t set id1 = id2
    *
    ERROR at line 1:
    ORA-00001: unique constraint (OPS$ORACLE.SYS_C001154403) violated
    

    John

  • Difference of path between primary key and a Unique Index

    Hi all

    Is there a specific way the oracle optimizer to treat differently the Primary key and Unique index?

    Oracle Version
    SQL> select * from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    
    SQL> 
    Sample data test for Index Normal
    SQL> create table t_test_tab(col1 number, col2 number, col3 varchar2(12));
    
    Table created.
    
    SQL> create sequence seq_t_test_tab start with 1 increment by 1 ;
    
    Sequence created.
    
    SQL>  insert into t_test_tab select seq_t_test_tab.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000;
    
    99999 rows created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> exec dbms_stats.gather_table_stats(USER_OWNER','T_TEST_TAB',cascade => true);
    
    PL/SQL procedure successfully completed.
    
    SQL> select col1 from t_test_tab;
    
    99999 rows selected.
    
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1565504962
    
    --------------------------------------------------------------------------------
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |            | 99999 |   488K|    74   (3)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T_TEST_TAB | 99999 |   488K|    74   (3)| 00:00:01 |
    --------------------------------------------------------------------------------
    
    
    Statistics
    ----------------------------------------------------------
              1  recursive calls
              0  db block gets
           6915  consistent gets
            259  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    
    SQL> create index idx_t_test_tab on t_test_tab(col1);
    
    Index created.
    
    SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB',cascade => true); 
    
    PL/SQL procedure successfully completed.
    
    SQL> select col1 from t_test_tab;
    
    99999 rows selected.
    
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1565504962
    
    --------------------------------------------------------------------------------
    | Id  | Operation         | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |            | 99999 |   488K|    74   (3)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T_TEST_TAB | 99999 |   488K|    74   (3)| 00:00:01 |
    --------------------------------------------------------------------------------
    
    
    Statistics
    ----------------------------------------------------------
              1  recursive calls
              0  db block gets
           6915  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    
    SQL> 
    Examples of test when using primary key data
    SQL> create table t_test_tab1(col1 number, col2 number, col3 varchar2(12));
    
    Table created.
    
    SQL> create sequence seq_t_test_tab1 start with 1 increment by 1 ;
    
    Sequence created.
    
    SQL> insert into t_test_tab1 select seq_t_test_tab1.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000;
     
    99999 rows created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB1',cascade => true);
    
    PL/SQL procedure successfully completed.
    
    SQL> select col1 from t_test_tab1;
    
    99999 rows selected.
    
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1727568366
    
    ---------------------------------------------------------------------------------
    | Id  | Operation         | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |             | 99999 |   488K|    74   (3)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| T_TEST_TAB1 | 99999 |   488K|    74   (3)| 00:00:01 |
    ---------------------------------------------------------------------------------
    
    
    Statistics
    ----------------------------------------------------------
              1  recursive calls
              0  db block gets
           6915  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    
    SQL> alter table t_test_tab1 add constraint pk_t_test_tab1 primary key (col1);
    
    Table altered.
    
    SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB1',cascade => true); 
    
    PL/SQL procedure successfully completed.
    
    SQL> select col1 from t_test_tab1;
    
    99999 rows selected.
    
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 2995826579
    
    ---------------------------------------------------------------------------------------
    | Id  | Operation            | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    ---------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT     |                | 99999 |   488K|    59   (2)| 00:00:01 |
    |   1 |  INDEX FAST FULL SCAN| PK_T_TEST_TAB1 | 99999 |   488K|    59   (2)| 00:00:01 |
    ---------------------------------------------------------------------------------------
    
    
    Statistics
    ----------------------------------------------------------
              1  recursive calls
              0  db block gets
           6867  consistent gets
              0  physical reads
              0  redo size
        1829388  bytes sent via SQL*Net to client
          73850  bytes received via SQL*Net from client
           6668  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          99999  rows processed
    
    SQL> 
    If you see here the same even as the statistics were gathered,
    * In the 1st table T_TEST_TAB, table always use FULL table access after creating indexes.
    * And in the 2nd table T_TEST_TAB1, table uses PRIMARY KEY as expected.

    Any comments?

    Kind regards
    BPat

    >
    * In the 1st table T_TEST_TAB, table always use FULL table access after creating indexes.
    * And in the 2nd table T_TEST_TAB1, table uses PRIMARY KEY as expected.
    >
    Yes - for the first table a full table scan will be used as the currently selected column is nullable and indexes do not include null values.

    The index can be used for the second query, since all the data (first column) is available between the index and there may be no NULL values because of the primary key. If you check constraints, you find that the there is now a CHECK constraint to ensure that the first column cannot be null.

    For a full and interesting discussion see the explanation of this and a related issue on the question I ask in this thread
    What SYS tables (not seen) contain the value NULL spec /not/ column definition? and my response he posted: 23 April 2012 09:02

    I ask the question is based on a question here which is similar to yours
    Columns becoming nullable after a fall of primary key?

Maybe you are looking for