Primary key,Froign key , Unique key

I want the answer of following questions.
1) Primary key create cluster index or simple index?
2) What is cluster index : I know only( cluster index stored record at physical level in sorted order) if there is another difference then tell me
3) Can I set relation ship with unique key if it is specified with NOT NULL constraints in a table.
4) Foreign key creates a index or not?

Hello
I want to be at least 6 inches taller, better looking and really good at playing the drums, but that's neither here nor there.
A simple please never hurts.
For answers to the first 2 I'd concentrate on the clusters section of the concepts guide as your understanding of what clusters are for and when they should be used appears to be lacking:
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96524/c11schem.htm#25479
and also have a look at this asktom thread:
http://asktom.oracle.com/pls/ask/f?p=4950:8:6996872588440689863::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:1308402202736
The last two questions, again you can find the info you need in the concepts guide but
3) Can I set relation ship with unique key if it is specified with NOT NULL constraints in a table.To set up a foreign key from one table to another, it needs to reference a primary key or a unique key in the target table, the NOT NULL constraint has very little to do with it. A very simple test will show this:
SQL> create table dt_test(id number);
Table created.
SQL> create table dt_test_fk(id number);
Table created.
SQL> create table dt_test_fk(id number, pk_id number);
Table created.
SQL> alter table dt_test_fk add constraint fk_dt_test_fk FOREIGN KEY(pk_id) references dt_test(id);
alter table dt_test_fk add constraint fk_dt_test_fk FOREIGN KEY(pk_id) references dt_test(id)
ERROR at line 1:
ORA-02270: no matching unique or primary key for this column-list
SQL> alter table dt_test add constraint uk_dt_test UNIQUE (id);
Table altered.
SQL> alter table dt_test_fk add constraint fk_dt_test_fk FOREIGN KEY(pk_id) references dt_test(id);
Table altered.
SQL> alter table dt_test modify(id number not null);
Table altered.
4) Foreign key creates a index or not? Creating a foreign key on a column does NOT automatically create an index on that column.
A primary key may create a new index. If an index is already available on the table and it can be used i.e the leading edge of the index holds the columns in the primary key, it will be used rather than creating a new one.
HTH

Similar Messages

  • Unique constraint error but key when inserting unique keys!

    Hi,
    I am tring to update an existing database with some older data, I am getting an error which complains about a unique constraint being violated although there is no voilation evident after testing.
    I am puzzled by this and was wondering if someone could give me any extra info on another possible cause.
    I googled but found that this error is caused by duplicating primary keys which I am not doing though I still get this error.
    I run this query then the update and get the output below:
    desc test_sales;
    desc sales_order;
    SELECT order_id FROM sales_order WHERE order_id IN (SELECT order_id FROM test_Sales);
    INSERT INTO sales_order
    (order_id,order_date,customer_id, ship_date,total)
    SELECT 
          order_id,
          order_date,
          cust_id,
          ship_date,
          total
    FROM
          test_sales;
    desc test_sales;
    Name                           Null     Type                                                                                                                                                                                         
    ------------------------------ -------- CUST_ID                                 NUMBER(6)                                                                                                                                                                                    
    OLD_SYSTEM_ID                           VARCHAR2(25)                                                                                                                                                                                 
    DESCRIPTION                             VARCHAR2(35)                                                                                                                                                                                 
    ORDER_DATE                              DATE                                                                                                                                                                                         
    SHIP_DATE                               DATE                                                                                                                                                                                         
    QUANTITY                                NUMBER                                                                                                                                                                                       
    ORDER_ID                       NOT NULL NUMBER(4)                                                                                                                                                                                    
    ITEM_ID                        NOT NULL NUMBER(4)                                                                                                                                                                                    
    SITE_COUNT                              NUMBER(2)                                                                                                                                                                                    
    TOTAL                                   NUMBER(8,2)                                                                                                                                                                                  
    PRODUCT_CODE                            NUMBER(6)                                                                                                                                                                                    
    LIST_PRICE                              NUMBER(8,2)                                                                                                                                                                                  
    12 rows selected
    desc sales_order;
    Name                           Null     Type                                                                                                                                                                                         
    ------------------------------ -------- ORDER_ID                       NOT NULL NUMBER(4)                                                                                                                                                                                    
    ORDER_DATE                              DATE                                                                                                                                                                                         
    CUSTOMER_ID                             NUMBER(6)                                                                                                                                                                                    
    SHIP_DATE                               DATE                                                                                                                                                                                         
    TOTAL                                   NUMBER(8,2)                                                                                                                                                                                  
    5 rows selected
    ORDER_ID              
    0 rows selected
    Error starting at line 7 in command:
    INSERT INTO sales_order
    (order_id,order_date,customer_id, ship_date,total)
    SELECT 
          order_id,
          order_date,
          cust_id,
          ship_date,
          total
    FROM
          test_sales
    Error report:
    SQL Error: ORA-00604: error occurred at recursive SQL level 1
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at line 8
    ORA-00001: unique constraint (MICHAELKELLY.SYS_C00210356) violatedMessage was edited by:
    Mike1981
    Message was edited by:
    Mike1981

    ORA-00001: unique constraint (MICHAELKELLY.SYS_C00210356) violated
    => check dba_cons_columns to see what the constraint actually exists off

  • Can foreign key refer to unique key?

    Hi....

    If you join that table x with table y using a
    WHERE x.pk_column = y.fk_columnpredicate. Then the rows with "matching" NULL's will not show up in the query result.
    But this has nothing to do with an FK referencing a UK.
    It has everything to do with how NULL's are treated in the SQL standard.
    A predicate like:
    NULL = NULLwill evaluate to FALSE (that's just how SQL treats NULL's in this case).

  • Is their a difference between primary key and unique key with not null valu

    What is the difference in having a column as primary key and having unique key with not null for the column.
    vinodh

    SBH wrote:
    For quick review, below is the link
    http://www.dba-oracle.com/data_warehouse/clustered_index.htm
    You appear to have stumbled on a site that is a mine of disinformation about Oracle.
    >
    It would be helpful, if you explain it too..thnx !!
    The site is wrong and makes up its own terminology as it goes along.
    If the value for clustering factor approaches the number of blocks in the base table, then the index is said to be clustered. http://www.oracle.com/pls/db112/search?remark=quick_search&word=clustered+index
    There is no create clustered index in Oracle.
    - Clustering factor affects the efficiency of an index.
    - There can be clustered tables that you can create indexes on.
    - An Index Organized table is a similar concept to the Microsoft SQL Server clustered index, but it isn't the same thing at all.

  • 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

  • Difference between Primary Key and Unique Key with NOT NULL constraint

    As both can be referred to another table.
    Apart from the difference that Primary Key can be only 1 and Unique keys can be multiple,
    is there any difference?
    Like in terms of type of Index?

    PARAG_C wrote:
    As both can be referred to another table.
    Apart from the difference that Primary Key can be only 1 and Unique keys can be multiple,
    is there any difference?
    Like in terms of type of Index?Technically there is almost no difference. Logically the two are often used for slightly different concepts.
    The PK (and with it the index) is often an ID column filled by a seqeunce. This key can then be refenced by foreign key constraints on other tables. it is very useful to have this as a meaningless technical construct. Because then the chance that such a ID needs to be changed is extremly slim.
    The UK (and with it the index) is often one or several columns that represent the logical key for the entity. Foreign key constriants should not point to this. THe chance that this attribute will be changed at some point in time is way higher then for a meaningless number (ID).

  • Difference between PRIMARY KEY and UNIQUE KEY with NOT NULL

    What is the difference between PRIMARY KEY and UNIQUE KEY with NOT NULL constraint?
    Message was edited by:
    Nilesh Hole

    Answer for the master!!!
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:8743855576462
    Thanks,
    Karthick

  • Difference between Unique key and Primary key(other than normal difference)

    Hello,
    1).Can any one tell me any other difference between Unique key and Primary key other than it having NULLs.
    2). What is the difference the words 'DISTINCT' and 'UNIQUE' in a sql query.
    Thanks in advance.

    Hi
    If you don't believe me than see the documentation in
    OTN.
    Ott Karesz
    http://www.trendo-kft.hu
    SQL> create table scott.tbl_clob
      2  (sss CLOB)
      3  /
    Tabelle wurde angelegt.
    SQL> insert into scott.tbl_clob values('wrwrwrw')
      2  /
    1 Zeile wurde erstellt.
    SQL> insert into scott.tbl_clob values('wrwrwrw')
      2  /
    1 Zeile wurde erstellt.
    SQL> select distinct sss from scott.tbl_clob
      2  /
    select distinct sss from scott.tbl_clob
    FEHLER in Zeile 1:
    ORA-00932: nicht übereinstimmende Datentypen
    SQL> select unique sss from scott.tbl_clob
      2  /
    select unique sss from scott.tbl_clob
    FEHLER in Zeile 1:
    ORA-00932: nicht übereinstimmende Datentypen
    SQL> select distinct to_char(sss) from scott.tbl_clob
      2  /
    TO_CHAR(SSS)
    wrwrwrw
    SQL> select unique to_char(sss) from scott.tbl_clob
      2  /
    TO_CHAR(SSS)
    wrwrwrw
    SQL>

  • Problems Engineering Surrogate Primary Key with Unique Key

    SDDM 3.3.0.747 with 2 problems (at least so far).  I am hoping that the problem is with this SDDM rookie and I have overlooked some setting. PROBLEM 1 I don’t want to start a religious debate about surrogate vs. natural keys but I am having a problem engineering both correctly from the logical model.  I am a rookie when it comes to SDDM but have many years of experience with Designer. By default I like to have both a natural UID  (UK) and a surrogate key based primary UID (PK) which is used for foreign keys.  The problem I am having with engineering is I can successfully engineer the surrogate PK’s, engineer the FK’s using the PK’s but cannot get the unique key to contain the surrogate keys in the child table.  If I check the identifying property in the relations, the PK columns and the UK columns are included in the child PK and the UK contains no columns. The Setup I have defined two reference entities, PROBABILITY and SEVERITY with natural unique keys defined.  I also have a child entity RISK_ASSESMENT with relationships back to the PROBABILITY and SEVERITY entities and both have the “Use surrogate keys:”: check box checked.  The unique key for the RISK_ASSESMENT entity includes the relationships back to PROBILITY and SEVERITY.  None of the entities have a PK or surrogate key defined and they all have the “Create Surrogate Key” check box checked.  In addition the following preferences are set: Data Modeler/Model/Logical   NOT Checked - Use And Set First Unique Key As Primary Key   NOT Checked – Name – Keep as the name of the Originating attribute   Checked – Entity Create Surrogate Key   Checked – Relationship Use Surrogate Key PROBLEM 2 When the foreign key columns are engineered I want the names to have a prefix “FK_” but they don’t.  Templates are set as follows: Data Modeler/Naming Standard/Templates   Foreign Key:  FK_{child}{parent}   Column Foreign Key:  FK_{ref column} Engineer to Relational Model/General Options   Checked - Apply name translation Marcus Bacon

    I have been switching between SD 4 EA1 and SDDM 3.3 trying to get things to work and trying out the template table for adding audit columns (really nice!).
    Concerning Problem1.  No matter what settings I use and whether I use SDDM 3.3 or SDI cannot get the FK columns to be included in the UK even though the relations are included in the UID in the entitty.  When I open the properties of the child table and click on the naming standards button and click ok it complains that the UK is not complete.  I add the FK columns to the UK and all is well including the naming standards.
    Concerning Problem 2.  Sometimes it engineers the names for FK's from the template and sometimes it doesn't.  Didn't see a pattern.  Gave up trying and used Naming Standards button.  I still had to change a few.
    The good new is, that after make changes needed in UK's and Column names of 18 tables, I know have everything deployed to Test except FK Indexes.  I think I have to do those by hand.
    Marcus Bacon

  • How shall we do validation for Unique Key and Multiple Primary Key?

    Hi,
    I have table created From EO in which one column is checked as Unique.
    How to do validation for column checked as Unique.
    I know how to do validation for column checked as primary key.
    Below is sample code for primary key validation
    if (getRvSize() != null)
    throw new OAAttrValException(OAException.TYP_ENTITY_OBJECT,
    getEntityDef().getFullName(), // EO name
    getPrimaryKey(), // EO PK
    "RvSize", // Attribute Name
    value, // Attribute value
    "AK", // Message product short name
    "FWK_TBX_T_EMP_ID_NO_UPDATE"); // Message name
    if (value != null)
    OADBTransaction transaction = getOADBTransaction();
    Object[] rvKey = {value};
    EntityDefImpl rvDefinition = xxczVAGCSRVSizingEOImpl.getDefinitionObject();
    xxczVAGCSRVSizingEOImpl rv =
    (xxczVAGCSRVSizingEOImpl)rvDefinition.findByPrimaryKey(transaction, new Key(rvKey));
    if (rv != null)
    throw new OAAttrValException(OAException.TYP_ENTITY_OBJECT,
    getEntityDef().getFullName(), // EO name
    getPrimaryKey(), // EO PK
    "RvSize", // Attribute Name
    value, // Attribute value
    "AK", // Message product short name
    "FWK_TBX_T_EMP_ID_UNIQUE"); // Message name
    What changes need to be done for above code in order to do the validation for Unique Key.
    I have one more Question
    How shall we do the Validation for Multiple Primary Key in a table?
    - Mithun

    1. If you just validate on one attribute like your unique key, then put your logic in the set<Your AttributeName) method
    2. If you want to do the cross validation ( like validating multiple attributes) then put your logic in the validateEntrity Method
    How to do that?
    1. Create a Validation View object.
    2. Associate your VVO to the VAM
    3. Create entity expert.
    4. Have method in entity expert for your validation (you would be calling AM and then VO execute the query and do the validation.
    5. You would be calling the Entity experty method from your EO either setMethods or validateEntity.
    I have given just the high level points.
    Hope this helps.
    Thanks,
    RK

  • Normal Indexes created for Primary/Unique Keys in Oracle8/8i

    I remeber prior to Oracle8, when we create a Primary/Unique Key constraints, an unique index will be created by default. But I am noticing now in 8/8i when we create either Primary or Unique key, only normal/simple index is created. We are not able to override this normal index either by dropping and recreating the index alone. I believe it would be pretty much better in case of performance if we have a unique index for this columns. Can anybody help why is it changed so in 8/8i??
    Thanks,
    R. M.

    Dear Rob,
    since your answer was helpful and since it was the only one I will grant you full points on that.
    Thanks again for your input. In case other developers should look this thread up being confronted
    with the same kind of problem, here is how we solved it:
    We added an artificial primary key (a number of type NUMC 8) to the table which is supposed to
    include the structure. This key alone takes care of the uniqueness of eacht entry.
    All the others fields that we want to have available for a fast direct access, including the ones
    from the included structure, are put together in a secondary index.
    best regards
    Andreas

  • PRIMARY KEY must be unique

    We tried to deploy with a JSP page and the following Errors appeared in log:
    [5400:4968:0613/153602:ERROR:connection.cc(733)] sqlite error 19, errno -2: PRIMARY KEY must be unique
    [5400:3224:0613/153603:ERROR:external_registry_loader_win.cc(90)] Missing value path for key Software\Google\Chrome\Extensions\jfmjfhklogoienhpfnppmbcbjfjnkonk.
    [5400:2964:0613/153607:ERROR:textfield.h(162)] NOT IMPLEMENTED
    Please guide us how to solve the issue.
    Thanks in advance,

    Which Jdev version do you use?
    11G Release 2
    11.1.2.2.0
    What kind of application  using which technology you are building?
    simplest one: Hello TimoHahn
    Which db do you use?
    Not yet use any DB
    Answered all your questions, Timo!
    How could we get a EAR file with " Hello World" out put?

  • Unique key violation i.e. primary key violation in JSF page

    Hi, I am using Jdeveloper 11.1.1.5.0 and working with adf fusion web application. I have created entity object and view object. In view object I have primary key and I have set it's type to DB sequence. THe problem is though the attribute is DB sequence. IN JSF page it show unique key violation i.e. primary key violation. Please help me

    So, do you have a trigger in the database that updates the value of the primary key? Or do you assign the value in some other way?
    You can check [url http://download.oracle.com/docs/cd/E16162_01/web.1112/e16182/toc.htm]the docs for information about the ways it can be done.

  • Primary/Unique key for GL_IMPORT_REFERENCES

    Hi all,
    We are on EBS11.5.10. I have the following requirement. I need to put a snapshot log on GL_IMPORT_REFERENCES which we will use to interface data to out reporting environment. Therefore i need to set a primary key on GL_IMPORT_REFERENCES, this is required for creating the snapshot log.
    Can anyone suggest what combination of fields would be unique for this table, as no unique key is set.
    TIA

    mma,
    but do you tie them in with ETL? or they're simply uniqe auto-number-like?
    Thanks
    I just found this:
    http://datawarehouse.ittoolbox.com/groups/technical-functional/informatica-l/re-about-oracle-bi-and-fact-tables-and-image-tables-1515935
    Looks like there's a new methodology for extending the DWH. I'm still looking into this, but I still think auto-numbering ROW_WID is a good idea.
    Mma, perhaps - could you provide me with an example or two to present this change. Thanks

  • Difference between Unique key and Unique index

    Hi All,
    I've got confused in the difference between unique index & unique key in a table.
    While we create a unique index on a table, its created as a unique index.
    On the other hand, if we create a unique key/constraint on the table, Oracle also creates an index entry for that. So I can find the same name object in all_constraints as well as in all_indexes.
    My question here is that if during creation of unique key/constraint, an index is automatically created than why is the need to create unique key and then two objects , while we can create only one object i.e. unique index.
    Thanks
    Deepak

    This is only my understanding and is not according to any documentation, that is as follows.
    The unique key (constraint) needs an unique index for achieving constraint of itself.
    Developers and users can make any constraint (unique-key, primary-key, foreign-key, not-null ...) to enable,disable and be deferable. Unique key is able to be enabled, disabled, deferable.
    On the other hand, the index is used for performance-up originally, unique index itself doesn't have the concept like constraints. The index (including non-unique, unique) can be rebuilded,enabled,disabled etc. But I think that index cannot be set "deferable-builded" automatic.

Maybe you are looking for

  • How to invoke a winword macro from jsp or servlet ?

    Hi, I have managed to open an word document from servlet. But I also need to run a macro to highlight some keywords once the document is open. Someone has suggested using runtime.exec(cmd) in the forum. Anyone can provide more details? Some code exam

  • In ibooks i want to open books to double page spread. How?

    My books, even in landscape mode, only show one page at a time.  I want to have double page spread.  How do I do that? Thanks, Tzipora

  • Old data transfer

    hello to every one ,,    client requriment , he want to move the old data to another ztable , like sales order data , delivery data , billing data , by doing this system will get free space , how to do this advance thanks

  • Date picker - is there a way to restrict the minuit select list to 1/4 hr

    Hi, When using date picker item with format 'DD-MON-YYYY HH24:MI', Is there a way to restrict the minuit select list on the calendar to 1/4 hr instead of 00 to 59. Example: 00,15,30,45 Thank you, Francis

  • Calling a BDC program in side a user-exit

    Hi all, I need to call a BDC program in side a user-exit of sales order change . i want to make user by calling this BDC program that it wont effect any of my other code's on that and that the customer wont be noticed with any inconvenience. i know t