When we use a unique index for PK?

I was reading this part of the manual oracle:

http://docs.Oracle.com/CD/B28359_01/server.111/b28310/indexes003.htm#ADMIN11727

I got confused because I was trying to research why sometimes, we want to create a primary key by using a unique index.

CREATE A UNIQUE MYTABLE_PK ON MYTABLE INDEX

(START_DT, ANNUAL)

LOGGING

TABLESPACE TBS_INDEX01

NOPARALLEL;

ALTER TABLE MYTABLE ADD)

CONSTRAINT MYTABLE_PK

KEY ELEMENTARY SCHOOL

(START_DT, ANNUAL)

WITH THE HELP OF INDEX MYTABLE_PK);

And sometimes we simply create the primary key without using a unique index.

ALTER TABLE MYTABLE ADD)

CONSTRAINT PK_MYTABLE

KEY ELEMENTARY SCHOOL

(START_DT, ANNUAL)

THE HELP INDEX);

When we use a unique index for PK?

James, you have returned to the question thread.

I apologize: I'm sorry, user8875620, your son has been hijacked. A UK or PK constraint needs an index. You can create a (unique or non-unique) explicitly, or you can let Uncle Oracle create it implicitly when you define the constraint.

Tags: Database

Similar Questions

  • (ORA-00955) conflict of naming for index and constraint when you use a unique index (.. desc,.. CSA)

    Hello

    indexes and constraints are in different namespaces, so it should be possible to give them the same name.

    In the following case that apparently does not work:

    create unique index orders_year_show_uq
      on orders (year desc, show_orders asc);
     
     alter table orders
      add constraint orders_year_show_uq unique (year, show_order);
    

    When I run these statement, I get a "SQL Error: ORA-00955: name is already used by an existing object". ""

    If I clean and I execute the same instructions as above with the only difference on the 2 line, using "asc year" instead of "year desc":

    
      on orders (year asc, show_orders asc);
    

    then it success.

    I can't explain it, you have an idea?

    Thanks in advance.

    Kind regards

    Giovanni

    First of all, you have show_orders in index and show_order in the constraint. I'll assume that it's a typo. Second, when you create constraint without index enhance the specification Oracle seeks indexes existing on the same set of columns in ascending order. If this index does not exist (and it's your case, since one of your columns to index is in descending order), Oracle tries to create one with the same name as the constraint. That's why you get ORA-00955: name is already used by an existing object. In general, you can specify explicitly the index name to force the Oracle by using the existing index. But it will not help you. If you issue

    ALTER table orders add unique constraint (year, show_orders) orders_year_show_uq using index orders_year_show_uq;

    You will get the ORA-14196: specified index cannot be used to apply the constraint.

    In any case, Oracle does not support using index DESC for PK/UK.

    SY.

  • CC 2015 Illustrator crashes when you use the function "save for Web".

    CC 2015 Illustrator crashes when you use the function "save for Web".

    Hello

    We have published a 19.0.1 hotfix that resolves this problem in discussion on this topic. Please apply the patch to your creative cloud application. The creative cloud application checks the update once a day, so you may see the update immediately.  If you want to force the check for an update at the beginning please logout and log back into the creative Cloud application.

    Link to 19.0.1 release notes: https://helpx.adobe.com/illustrator/kb/illustrator-cc-2015-crash-bug-fixes-19-0-1.html

    Kind regards

    Ashutosh

    The name of the Illustrator team engineering

  • How to get LR using a unique name for each file?

    Hey there,

    I see that LR does not change the name of the file when there is already a file with the same name in the import file, but once you choose another folder it does not matter the file with the original name. I just realized that over the years using folders such as photos 2009 Photos 2010 and so forth, I have three or four times the files with the same name. Is there a way to tell LR to always use unique names when importing?

    Use a naming date-description model - sequence.ext to rename as you import (or if you prefer after importation). This means that you have never duplicates unless you for some weird reason use the same description for two sets of files on the same day. And if you need to do exactly that, just the starting number of the second/third batch of files be a number greater than previous batch on the same day.

    You can configure what ever format naming you want in file rename dialogue and have as a default.

    Leaving the file names as they come out of the device application in big trouble as invariably they're going to duplicate, which is not an even if good idea in different folders.

    F2 to rename the dialog when in the library.

  • How can I clear the browser history when you use the custom settings for history?

    When my history option is set to "Use the custom settings for history", the options page has no link to "clear recent history". There was formerly a menu option, but that seems to be gone now with Firefox 29. Is my only option to access the dialog box, clear the history all to change the historical option to history to remember and then change it back? Is there another way to access the option erase history all?

    I think you can get the menu bar by pressing the ALT key. If you want to return permanently, click View > toolbars and check menu bar.

  • When you use USB foot control for transcription intermittently continues to play even when released. Tried the new foot controller.

    Recently, I upgraded my wife to a new pc with Windows 7 Home Premium on it.  The package of trancription she uses is WinScribe.  For knowledge, we kept his old Office XP with Word 2002.  After the IT person to society that it contracts for all their software set up and install a spell checker medical all seems to work well.  Well now, we just have a question.  She uses and uses an Infinity IN-USB-2 foot controller.  The question is when it plays its reports, intermittently when it leaves upward on the pedal to play that the report continues to play.  We have installed a new pedal, always with the same problem.  These controllers do not come with a dedicated driver, but are recognized by Windows.  Don't know if it's a problem of Windows 7 or not, but before, it was to use Windows XP with the same transcription software, the same product office and same foot controller without problem.  As a side note, my reason to replace his old computer was XP got to where she acted as if she had alzhiemers.  Has raced in many analyses of virus and malware scans with various products.  No permit.  Has happened to another pc, I have too.  Anyone who deals with this?

    Hello Larry,.

    Thanks for posting of query in Microsoft Community.

     
    I suggest you to contact Infinity IN-USB-2 feet and check with them.
    Support by email
     
    Hope the helps of information.
     
    Thank you
  • Why choose wrong explain plan when there is a unique index

    SQL > create table test in select * from dba_objects;

    Table created.

    SQL > create table test1 in select * from user_objects;

    Table created.

    SQL > create index unique i_test_1 on test (object_id);

    The index is created.

    SQL > exec dbms_stats.gather_table_stats (user, 'TEST');

    PL/SQL procedure successfully completed.

    SQL > exec dbms_stats.gather_table_stats (user, 'TEST1');

    PL/SQL procedure successfully completed.

    SQL > set autot trace
    SQL > select test1.* from test, test1 where test.object_id = test1.object_id;

    23037 selected lines.


    Execution plan
    ----------------------------------------------------------
    Hash value of plan: 3995284093

    -------------------------------------------------------------------------------
    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
    -------------------------------------------------------------------------------
    | 0 | SELECT STATEMENT | 23038 | 2114K | 77 (12) | 00:00:01 |
    | 1. NESTED LOOPS | 23038 | 2114K | 77 (12) | 00:00:01 |
    | 2. TABLE ACCESS FULL | TEST1 | 23038 | 2002K | 70 (3) | 00:00:01 |
    |* 3 | INDEX UNIQUE SCAN | I_TEST_1 | 1. 5. 0 (0) | 00:00:01 |
    -------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------

    3 - access("TEST".") OBJECT_ID '= 'TEST1'.' OBJECT_ID')


    Statistics
    ----------------------------------------------------------
    494 recursive calls
    0 db block Gets
    26457 consistent gets
    0 physical reads
    0 redo size
    1090589 bytes sent via SQL * Net to client
    17270 bytes received via SQL * Net from client
    1537 SQL * Net back and forth to and from the client
    5 kinds (memory)
    0 sorts (disk)
    23037 rows processed


    SQL > drop index i_test_1;

    The index is deleted.

    SQL > create index i_test_1 on test (object_id);

    The index is created.

    SQL > set autot trace
    SQL > select test1.* from test, test1 where test.object_id = test1.object_id;

    23037 selected lines.


    Execution plan
    ----------------------------------------------------------
    Hash value of plan: 845425162

    --------------------------------------------------------------------------------
    --

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time
    |

    --------------------------------------------------------------------------------
    --

    | 0 | SELECT STATEMENT | 23038 | 2114K | 99 (6) | 00:00:02
    |

    |* 1 | HASH JOIN | 23038 | 2114K | 99 (6) | 00:00:02
    |

    | 2. FULL RESTRICTED INDEX SCAN FAST | I_TEST_1 | 49887 | 243K | 27 (4) | 00:00:01
    |

    | 3. TABLE ACCESS FULL | TEST1 | 23038 | 2002K | 70 (3) | 00:00:01
    |

    --------------------------------------------------------------------------------
    --


    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------

    1 - access("TEST".") OBJECT_ID '= 'TEST1'.' OBJECT_ID')


    Statistics
    ----------------------------------------------------------
    1 recursive calls
    0 db block Gets
    1936 complies
    411 physical reads
    0 redo size
    1090589 bytes sent via SQL * Net to client
    17270 bytes received via SQL * Net from client
    1537 SQL * Net back and forth to and from the client
    0 sorts (memory)
    0 sorts (disk)
    23037 rows processed

    I think the hash join is the real plan, why choose nest loop where there is a unique index.

    Jinyu wrote:
    I think that thought cbo cost single scan index is 0, so loop nest is less expensive than the hash join, but I do not know why here costs 0

    Jinyu,

    You are right - in a nested loop, the CBO gives unique access by unique index value slightly cheaper than the same access by a non-unique index--essentially subtracting 1 of the normal cost.

    It is one of the reasons why you only need to create a no unique index to support a unique constraint, if you have a very good reason - if you modify a unique index that is not unique, change of costs and execution of some paths may change.

    Concerning
    Jonathan Lewis

  • explain query plan uses no unique index with where condition

    Hi all

    I use in the 10.2.0.5 oracle database Enterprise edition 64-bit on 64-bit windows server 2008.

    I'm following this tutorial on my own table

    Guide to understanding Oracle QUERY PLAN - 10 minutes

    my questions are below

    Analyze table LIB_CLASSIFICATIONS compute statistics;
    explain plan for  SELECT class_id  FROM lib_classifications WHERE class_no = '538' ;
    select * from table(dbms_xplan.display);
    

    the result is less than

    Hash value of plan: 3022072076

    -----------------------------------------------------------------------------------------

    | ID | Operation | Name                | Lines | Bytes | Cost (% CPU). Time |

    -----------------------------------------------------------------------------------------

    |   0 | SELECT STATEMENT |                     |     1.    10.     5 (0) | 00:00:01 |

    |*  1 |  TABLE ACCESS FULL | LIB_CLASSIFICATIONS |     1.    10.     5 (0) | 00:00:01 |

    -----------------------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):

    ---------------------------------------------------

    1 - filter ("CLASS_NO" = '538')

    DESC LIB_CLASSIFICATIONS

    Name of Type Null

    ----------------- -------- -------------

    CLASS_ID NOT NULL NUMBER (10)

    CLASS_DESC VARCHAR2 (50)

    REMARKS VARCHAR2 (250)

    CLASS_NO VARCHAR2 (20)

    CLASS_TYPE VARCHAR2 (10)

    CREATE_USER VARCHAR2 (10)

    MODIFY_USER VARCHAR2 (10)

    CREATE_DATE DATE

    MODIFY_DATE DATE

    CLASS_CATEGORY_ID VARCHAR2 (10)

    class_id has a primary key.

    now when I remove the condition where the query, the result is lower;

    Analyze table LIB_CLASSIFICATIONS compute statistics;
    explain plan for  SELECT class_id  FROM lib_classifications ;
    select * from table(dbms_xplan.display);
    

    the result is less than

    Hash value of plan: 262704430

    ------------------------------------------------------------------------------------

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |

    ------------------------------------------------------------------------------------

    |   0 | SELECT STATEMENT |             |  1558.  6232.     2 (0) | 00:00:01 |

    |   1.  FULL RESTRICTED INDEX SCAN FAST | SYS_C005653 |  1558.  6232.     2 (0) | 00:00:01 |

    ------------------------------------------------------------------------------------

    now it's using indexes with INDEX FAST FULL SCAN.

    I need the index using the WHERE condition as well.

    How to do this?

    Thank you.

    you have indexes on the column class_id not on class_no column how u would expect index to use when there is no index on the column class_no

  • unique index for several columns

    Hi all

    We have a requirement for our application, to add a single search box, which searches more than 1 table of different columns. The way in which we have now implemented, is the following (simplified example):
    Select *.
    WCP
    where instr(ename,:SEARCH) > 0
    or instr(job,:SEARCH) > 0
    or...

    This approach is relatively slow, of course. I want to change it, using the text of the Oracle. Can you give me advice what kind of index, must be used? Our requirement:
    -index must continue to be up-to-date (a few seconds)
    -research must be
    -case insensitive preference
    -number of columns to be indexed: aprox. 20 in a table

    I heard once you can make a function, with all the columns you want to index. This function generates an xml document, and you can use this function to create an Oracle text index. However, I can't seem to find how I can implement that. Or is there a better aproach?

    Thanks again for your help!

    You can use a multi_column_datastore, that generates xml documents as you describe in the scenes. You can also use the transactional option or sync (on validation) with optimization. See the simplified example with only two columns below that matches what you provided. You can find further information and examples for the multi_column_datastore in the online documentation.

    SCOTT@orcl_11gR2> begin
      2    ctx_ddl.create_preference ('emp_ds', 'multi_column_datastore');
      3    ctx_ddl.set_attribute ('emp_ds', 'columns', 'ename, job');
      4  end;
      5  /
    
    PL/SQL procedure successfully completed.
    
    SCOTT@orcl_11gR2> alter table emp add (any_column varchar2(1))
      2  /
    
    Table altered.
    
    SCOTT@orcl_11gR2> create index emp_idx
      2  on emp (any_column)
      3  indextype is ctxsys.context
      4  parameters
      5    ('datastore emp_ds
      6        transactional')
      7  /
    
    Index created.
    
    SCOTT@orcl_11gR2> variable search varchar2(100)
    SCOTT@orcl_11gR2> exec :search := 'CLARK'
    
    PL/SQL procedure successfully completed.
    
    SCOTT@orcl_11gR2> select ename, job from emp
      2  where  contains (any_column, :search) > 0
      3  /
    
    ENAME      JOB
    ---------- ---------
    CLARK      MANAGER
    
    1 row selected.
    
    SCOTT@orcl_11gR2> exec :search := 'CLERK'
    
    PL/SQL procedure successfully completed.
    
    SCOTT@orcl_11gR2> select ename, job from emp
      2  where  contains (any_column, :search) > 0
      3  /
    
    ENAME      JOB
    ---------- ---------
    SMITH      CLERK
    ADAMS      CLERK
    JAMES      CLERK
    MILLER     CLERK
    
    4 rows selected.
    
  • When I use a special rendering for my xfaForm I can't have the full button or finished when I call workspace process?

    Hello

    I have a 'FlexriverInvoice' process that contains two steps first change a budget ID and pass the xfaForm, then a second step use the rendering service that return a pdf.

    I created a new process 'InvoiceCall', he uses 'FlexriverInvoice' service in the first stage and second he use a service of writeXml that put a coded XML on my "c:" in the advanced settings of xfaForm of my "InvoiceCall" of the process, I enable rendering with 'FlexriverInvoice '.

    When I call the process of work space, I have the button submit on the pdf file and when I click there is no action.

    When I put the InvoiceCall xfaForm rendering"default process, I have the finished button and if I click I have xml texts on my"c: ".

    the .lca process is attached to this message (Please remove the extension pdf)

    Thanks for your help

    Hamza

    "I'm sorry, but I did not understand how to find the url to submit.

    It is a property of the button submit on your XDP.

    Jasmine

  • Firefox crashed, I reinstalled and now when I use a new tab for an address I can not get it to load by clicking on enter. How to activate it?

    When I start typing in the address of my story captures the correct address, but the only way that I get to load is hitting the arrow button in the address bar. I want to be able to hit enter

    Hey Susan-MPC.

    Have you tried to start Firefox in Mode safe? Key 'shift' startup of Firefox. It could be related to an extension. Then you should read the extensions, themes and problems of hardware acceleration to resolve common troubleshooting Firefox problems.

    I see you are using an older version of Firefox as well. You can update. There are many advantages to the performance of the latest version of the browser.

    Hope this helps!

  • When you use Boinc computer software for sharing at high temperature

    I have a z600 with 2 x 5550 cpu and 24 GB of ram.  When I try to run it above 60% load it reached 91 c with the Core Temp software.

    The computer is clean and free of dust. Is this normal?

    CoreTemp also shows a value for Tj max.  That is your processor?  CoreTemp is adjustable to show the difference between Tj max and the base time.  This temperature depends on the processor.

    Processors will run hot when you're stressed, it's supposed to get maximum performance.  I ran systems to 100% of CPU load for weeks at a time, on several systems, and the base temperature max was around 10 degrees c (or more) below Tj max.

    If your CPU is running closest to Tj max, some things could contribute to reduce the time.  Download the dust of the case and the heat sinks.  The fans run OK?  Have you ever removed the radiators of processors, and if you did, replace you the thermal paste?

    Either way, if we remove the CPU heatsink, Intel recommends cleaning the processors and heatsinks of the old thermal paste and apply the new paste.  The old dough hardens and does not heat, well, if the radiator is replaced by the old dough.  I don't think it would make a big difference, and sometimes simply put the radiator on a CPU with old dough, until what I tested a system and found the CPU was running 1 deg C below Tj max.  That's never happened before, so I cleaned the old dough off the CPU and the heatsink, put some new goodies on it, and then the CPU ran at least 12 degrees C below Tj max at 100% load.  FOR INFO.

  • Can we use licenses unique App for a company?

    Hello Sir,

    We run a small business with a team of 10 people. I need 5 licenses of creative cloud. Now, cloud creative teams is more expensive and has more features that I don't need (such as the deployment of the license, 100 GB cloud storage etc.).

    I just though that, if I could buy individual 5 licenses and use it to people on my team. It will work or not.

    In my view, there is no problem at all.

    If possible, please write us @ [email protected]

    And call for the 9899859761

    Thank you!

    Sunil Kumar

    Yes. See this link:

    http://www.Adobe.com/creativecloud/business/teams.html

  • problem in the form of master-detail when you use the ADF table for detail

    Hello

    jdev version - 11.1.2.1.0


    I create master shape detail using datacontrol drag as ADF master shape secondary Table.


    Now when I create a new line in the detail table using the key CreateInsert a new empty row created on top of the secondary table.

    and other show line that the previous record data based on the master.

    problem is I want to when I click on the createInsert button all the line of the secondary table must be empty and what line to fill two or three user then validate.



    Thanks in advance

    Hello

    If a secondary table has data, then createInsert adds to them. If you want to hide the existing lines, create a new instance of the View object and set the option "extract database" to "No. Rows. Use an af:switcher to change the specified table when the user clicks the createInsert button. There is some coding needed to have this use case in the ADF, but its essentially declarative. Bottom line, is that there is no option automated other than to create new lines in a separate page or dialog box if you are bothered by existing lines

    Frank

  • Transform a no Unique Index in a single index

    Hello

    Version: 11.2.0.4.0 Enterprise Edition

    We got a non-unique Index for a primary key constraint. I would like to change that in a unique index. I know that you can not change the index to change. Is the only way to disable the primary key, delete the index and re-enable the constraint or is there a better solution? It is a 24/7 platform.

    sql_colder

    Windows service exist for a reason.

    You can also create clues online in an operational database.

    There is no other method outside the use of DBMS_REDEFINITION.

    Think about it: what is the business case to change the index?

    -----------

    Sybrand Bakker

    Senior Oracle DBA

Maybe you are looking for

  • Apple TV won't let me access the Disney shows

    I already went through the code and connected to my direct tv account a few days ago. Everything worked very well! I was able to access all the Disney watch I wanted. But today after I just made a movie on the Disney app, I went to click on the follo

  • How do I change the program used to open mailto links in windows 8

    I would like to use Firefox to open Mailto links in Windows 8. I found this article of support, but it is not relevant for Windows 8: https://support.mozilla.org/en-US/kb/change-program-used-open-email-links?esab=a & as = aaq When I open Control Pane

  • YouTube is not displayed correctly

    When I OPET youtube in firefox it shows like this http://img97.imageshack.us/img97/8370/captureas.jpgIE it oppens regularly in firefox, I'm thsis problem, how to fix?

  • Pavilion dv6 6160sx: drivers Hp Recovery Manager

    Hello! About a year ago I have reinstall my windows7 Home premium and I lost my driver as Manager Hp recovery, webcam, microphone, audio beats, etc. radeon graphics card. Please help me! Thank you

  • IMac, remove the screen and use your Apple TV

    I send my iMac screen 2011 for repair.  I would use my Apple TV mirrored my iMac screen {(aucun écran LCD installé) to a HD TV while my screen is out for repair.} Is this possible?  Or not because I have to be able to see "Air" on my imac to get ther