About Primary key

We declare primary key in our table..but why do we use Constraint with primary key? and what is the meaning of constraint in oracle

Hi,
Constraints is some kind of rule and those rule have different category, which is define as Key.
Like.
If you r define Primary key that time rule would be different and for other like unique, not null rule would be different.
So we can characterize the constraint with different role and definition.
Regs,
Brij

Similar Messages

  • Basic doubt about Primary Key/Foreign Key in Oracle Tables

    Hi,
    I have a doubt whether Primary Keys/Foreign Keys are allowed in Oracle. Some of the people I know are telling me that Oracle does not encourage having Primary Keys/Foreign keys in its database tables.
    However if I go to the ETRM and look for information about some of the Oracle Tables, I am informed that Primary Keys do exist. However I am being told that ETRM is not a reliable way of having correct information about table structure.
    It would be great if any one of you provides me with some insight in this. Any pointers to a document would be great.
    Thanks

    It is not that PK/FKs are disallowed in Oracle Apps (there are some on the standard Oracle Apps tables), but they are typically not used. I am not positive what the logic behind this is, but my guess is that it was party due to the earlier versions of Oracle Apps pre-dating declarative database referential integrity in Oracle DB and also on performance issues with the standard referential integrity with the earlier versions of declarative database referential integrity.
    As far as eTRM is concerned - I understood that the data is based on a design repository rather than a physical Oracle Apps DB. So all of the information in there is logically correct, but not necessarily enforced via the standard Oracle DB declarative referential integrity (rather by the application code or APIs).

  • Basic doubt about Primary Keys/Foreign Keys in Oracle Tables

    Hi,
    I have a doubt whether Primary Keys/Foreign Keys are allowed in Oracle or not. I have been informed that Oracle does not encourage having Primary Keys/Foreign keys in its database tables. Instead it urges users to have unique constraints on the requisite columns.
    However if I go to the ETRM and look for information about some of the Oracle Tables, I am informed that Primary Keys do exist. At the same time, I am being told that ETRM is not a reliable way of having correct information about table structure (at least the Primary Key information).
    It would be nice if any one of you provides me with some insight in this. Any pointers to a document would be welcome.
    Thanks

    FYI,
    There is seprate forum for Core Sql quieries
    PL/SQL
    Thanks

  • Concept about Primary Key index

    I have a partitioned table as follow:
    CREATE TABLE TEST
    (TEST_KEY NUMBER(10,0) NOT NULL
    ,FOREIGN_KEY NUMBER(10,0) NOT NULL
    ,PARAM_ID NUMBER(10,0)
    ,PARAM_VALUE VARCHAR2(256)
    PARTITION BY HASH (operation_key) PARTITIONS 15
    STORE IN (TEST_R1_TS, TEST_R2_TS, TEST_R3_TS, TEST_R4_TS, TEST_R5_TS)
    CACHE
    I also created a partitioned index for the TEST_KEY to be used as primary key index.
    CREATE INDEX TEST_PK_IDX ON PARAMETER_1(TEST_KEY) LOCAL
    STORE IN (TEST_i1_ts, TEST_i2_ts, TEST_i3_ts, TEST_i4_ts, TEST_i5_ts);
    When I try to run alter table to add primary key, I got index not exist error?
    SQL> alter table TEST add (constraint test_pk primary key (test_key) using index test_pk_idx);
    alter table parameter_1 add (constraint pa1_pk primary key (parameter_key) using index pa_pk_idx)
    ERROR at line 1:
    ORA-01418: specified index does not exist
    BUT, I could find my index in the USER_INDEXES table...
    SQL> select index_name from user_indexes where index_name like '%TEST_PK%';
    INDEX_NAME
    TEST_PK_IDX
    Why? Help is very appreciated.
    Thank you in advanced.

    check the names of the tables in the script you give ... they are different for the table and the index. When you add the constraint the table name and column name mysteriously change in the error message, so I think that you aren't showing us what actually happened.

  • Question about Primary Key

    HI
    I'm going to build a Database to automate center in my university
    The Database version is Oracle 10g v2
    Which data type of primary key should I user?
    I used number in past but I heard there is more efficient data type for this purpose
    Thanks

    BINARY_FLOAT and BINARY_DOUBLE are designed to store floating point numbers. If you are generating synthetic primary keys using a sequence, you are generating integers. It makes no sense from a data modeling perspective to store integer data in floating point fields. And it is exceptionally dangerous if a value gets rounded unexpectedly (floating point numbers lose precision for the trailing bits)
    You'll have to clarify for me what "more helpful for indexing" means. As far as storage space goes, there may be some space savings using a BINARY_FLOAT or BINARY_DOUBLE if you have very large primary key values, but there will be a space penalty for most "normal" sequence-generated values, i.e.
    SQL> create table x (
      2    col1 number,
      3    col2 binary_float,
      4    col3 binary_double
      5  );
    Table created.
    SQL> insert into x values( 1, 2, 3 );
    1 row created.
    SQL> select length(col1), length(col2), length(col3) from x;
    LENGTH(COL1) LENGTH(COL2) LENGTH(COL3)
               1            8            8
    SQL> insert into x values (1e20, 1e20, 1e20 );
    1 row created.
    SQL> select length(col1), length(col2), length(col3) from x;
    LENGTH(COL1) LENGTH(COL2) LENGTH(COL3)
               1            8            8
              21           15            8
    SQL> select * from x;
          COL1       COL2       COL3
             1   2.0E+000   3.0E+000
    1.0000E+20   1.0E+020   1.0E+020So it takes 8 times the storage to store a 1 in a BINARY_FLOAT or BINARY_DOUBLE than it does to store that in a NUMBER column. But it takes less space if you're storing values like 1e20 (a 1 with 20 0's). If you're storing values large enough to get the space benefit, however, you're going to have rounding issues that will cause the application not to function as you'd expect which is presumably a much greater problem than a bit of wasted disk space.
    Justin

  • Comp. Primary key class-field mapping to DB columns problem.(EJB 2.0 CMP)

    Hi!
    I have deal with EJB 2.0 CMP bean.
    I have a composite PK so use the java class to store it. And there is a corresponding field in the Entity Bean with its primary key class type.
    The problem is: when deployment tool creates sql query for the findByPrimaryKey(PKClass ck)
    where ck is an object with 3 fielde : a_id, b_id, c_id.
    it says:
    <sql>SELECT "ck" FROM "MyTable" WHERE "ck" = ? </sql>
    And it means by the "ck" simple a column in DB but NOT the composite key which has to be splited into 3 different fields. So the container can't do the proper mapping.
    Does anyone know solutions?

    I was wrong about primary key class fields, take a look at Ejb2.0 Specification (10.8.2):
    The primary key class must be public, and must have a public constructor with no parameters.
    All fields in the primary key class must be declared as public.
    The names of the fields in the primary key class must be a subset of the names of the container-managed
    fields. (This allows the container to extract the primary key fields from an instance�s container-managed
    fields, and vice versa.)
    Right now I'm using BMP and I don't have this problems. Primary keys, calculated fields and types not supported by the DB can be easily achieved. But I understand your interest on CMP, is clearly evolving!

  • UNIQUE INDEX and PRIMARY KEYS

    Hi Friends,
    I am confused about primary keys.
    What is the purpose of this key again? I know it is used for unique constraints.
    Supposing I have a table with two (2) columns which are each indexed as unique.
    Then they can me both candidate at primary key right?
    So why do I need a primary key again? when I have 2 columns which are uniquely index?
    Thanks a lot

    A UNIQUE index creates a constraint such that all values in the index must be distinct. An error occurs if you try to add a new row with a key value that matches an existing row. This constraint does not apply to NULL values except for the BDB storage engine. For other engines, a UNIQUE index allows multiple NULL values for columns that can contain NULL
    The differences between the two are:
    1. Column(s) that make the Primary Key of a table cannot be NULL since by definition; the Primary Key cannot be NULL since it helps uniquely identify the record in the table. The column(s) that make up the unique index can be nullable. A note worth mentioning over here is that different RDBMS treat this differently –> while SQL Server and DB2 do not allow more than one NULL value in a unique index column, Oracle allows multiple NULL values. That is one of the things to look out for when designing/developing/porting applications across RDBMS.
    2. There can be only one Primary Key defined on the table where as you can have many unique indexes defined on the table (if needed).
    3. Also, in the case of SQL Server, if you go with the default options then a Primary Key is created as a clustered index while the unique index (constraint) is created as a non-clustered index. This is just the default behavior though and can be changed at creation time, if needed.
    So, if the unique index is defined on not null column(s), then it is essentially the same as the Primary Key and can be treated as an alternate key meaning it can also serve the purpose of identifying a record uniquely in the table.

  • Urgent expalantion about surrogate keys

    Hi,
    i had a big doubts about primary keys and surrogate keys, i don't know anything about surrogate keys.
    need information on above..
    Regards,
    sh

    sh wrote:
    Hi,
    i had a big doubts about primary keys and surrogate keys, i don't know anything about surrogate keys.
    need information on above..
    Regards,
    shhttp://en.wikipedia.org/wiki/Surrogate_key

  • About Automatic generation of Primary key

    I have created one Z table. Its composite primary keys are vkorg
    and Sales Representive Number. I have to assign Sales Representive number
    through system. How it should be done?
    Message was edited by:
            Nilesh Vakil

    Nilesh , You asked the Same question in ABAP General
    Please Refer the link.
    Re: About Automatic Generation of Primary key
    Regards
    Rusidar S
    Message was edited by:
            Rusidar Subramani

  • About sequences substituting primary key values

    I've created trigger:
    TRIGGER EMPLOYEES_TRG BEFORE INSERT ON EMPLOYESS
    FOR EACH ROW
    BEGIN
    SELECT employees_seq.nextval
    INTO :new.nr
    FROM dual;
    END;
    following statement works just fine in SQL Worksheet:
    insert into employees(Name, Surname) values ('M','C')
    but when I try to make a swing client from application module using fields from entityView it seems that trigger doesn't fire as I commit. maybe the adequate statement
    generated using ADF Business components doesn't generate "employees(Name, Surname)"?
    The question is how to make my tables primary key get increased using trigger when I make a client form from two fields: Name, Surname and create and commit buttons.. ?

    HI Mario,
    your primary key in the entity object needs to be of DBSequence type.
    It will show as a negative number in the form but when doing a commit the Trigger will catch it and change the value to sequence number.
    Carl

  • How my EntityBean knows about its primary key?

    Well, i found a dubious place in my EntityBean.
    I wrote an ItemBean with some simple getter and setter methods.
    It has 3 instance variables:
    - String id, (primary key)
    - String productId,
    - String name
    Here is the code of my application client:
    Context init = new InitialContext();
    Object ref = init.lookup("java:comp/env/ejb/ItemBean");
    ItemRemoteHome home = (ItemRemoteHome)PortableRemoteObject.narrow(
        ref,ItemRemoteHome.class);
    ItemRemote remote = home.create("x","y","z");
    String key = remote.getPrimaryKey();
    System.out.println(key);The code works well, but i dont know how my EntityBean knows its primary key when
    i call the remote.getPrimaryKey() method.
    i traced the method invoking and checked the server log.
    // when calling home.create()
    the bean's constructor is called to create a bean
    setEntityContext() is called. but now the primary key in the entity context is null
    ejbCreate() and ejbPostCreate() is called
    ( i inserted a row to the DB in the ejbCreate() method)
    ejbStore() is called
    // when calling remote.getPrimaryKey();
    ejbLoad() is called, so all the bean's instance variables are refreshed
    but non of the getter or setter methods are called
    I think that the primary key is taken from the entity context instead of the bean.
    but when did the entity context get the primary key?
    I never tell the bean that its primary key is its id.
    Stange, isnt it?

    I never tell the bean that its primary key is its id.You should be returning the primary key from the ejbCreate method. The container picks that up and pops it into the EJB context.

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

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

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

  • What is the diffrence between Row id and primary key ?

    dear all
    my question is about creating materialized views parameters (With Rowid and
    With Primary kry)
    my master table contains a primary key
    and i created my materialized view as follow:
    CREATE MATERIALIZED VIEW LV_BULLETIN_MV
    TABLESPACE USERS
    NOCACHE
    LOGGING
    NOCOMPRESS
    NOPARALLEL
    REFRESH FAST ON DEMAND
    WITH PRIMARY KEY
    AS
    SELECT
    BCODE ID, BTYPE BTYPE_ID,
    BDATE THE_DATE,SYMBOL_CODE STOCK_CODE,
    BHEAD DESC_E, BHEADARB DESC_A,
    BMSG TEXT_E, BMSGARB TEXT_A,
    BURL URL, BTIME THE_TIME
    FROM BULLETIN@egid_sefit;
    I need to know is there a diffrence between using (with row id) and (with primary key) on the performance of the query?

    Hi again,
    fast refreshing complex views based on rowids, according to the previous subject.
    (You're example shows that) are not possible.
    Complex remote (replication) snapshots cannot be based on Rowid too.
    for 10.1
    http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_6002.htm#sthref5054
    for 10.2
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_6002.htm#sthref6873
    So I guess (didn't check it) that this applies ONLY to replication snapshots.
    This is not documented clearly though (documentation bug ?!)
    Documentation states that the following is generally not possible with Rowid MVIEWS:
    Distinct or aggregate functions
    GROUP BY or CONNECT BY clauses
    Subqueries
    Joins
    Set operations
    Rowid materialized views are not eligible for fast refresh after a master table reorganization until a complete refresh has been performed.
    The main purpose of my statements was to try to give a few tips how to avoid common problems with this complex subject, like for example: being able to CREATE an MVIEW with fast refresh clause does not really guarantee that it will refresh fast in the long run (reorganisation, partition changes) if ROWID based, further the rowid mviews have limitations according to the documentation (no group by, no connect by, link see above) plus fast refresh means only to use filter columnns of the mview logs, plus for aggregates you need additional count (*) pseudo columns.
    kind regards
    Karsten

  • Primary key vs Secondary key - why would a rpt hit one as to the other?

    Post Author: kevans
    CA Forum: Data Connectivity and SQL
    Here's an issue that surfaced when using CRW10, happens with XI as well, but not an issue with CRW8 - each one is hitting the same SQL Server db.
    I discovered something today and I'm not sure if this might be the road to a solution, however, I don't know enough about SQL Server and/or Crystal.  First, my reports seem fairly simple in nature, I don't think I'm pulling a million rows of data, maybe but doubt it.  So I run report ABC and I see blocking issues in SQL Server Enterprise Mgr.  If I run report XYZ that isn't too much different than ABC, I do not see blocking issues.  Hmm, what could be different?  In SQL-Mgr when I look at the SPID info generated by the report I can see the tables the report is referencing and below is what I discovered.
    The one difference I see is under the "Index" column - the report blocking shows "XPKcall_req" where call_req is the table I'm pulling from.  The report that IS NOT blocking shows call_req_x0.  I checked with our dba and he wasn't sure, other than to say XPK is the primary key index.  Okay, then why is one report hitting the primary key index (whatever that is) and the other isn't?  In Crystal I'm not sure how to tell it to stop doing this, I tried shaking my finger and yelling but like my kids this does little.
    Any ideas, with the report that is?

    Post Author: kevans
    CA Forum: Data Connectivity and SQL
    Here's an issue that surfaced when using CRW10, happens with XI as well, but not an issue with CRW8 - each one is hitting the same SQL Server db.
    I discovered something today and I'm not sure if this might be the road to a solution, however, I don't know enough about SQL Server and/or Crystal.  First, my reports seem fairly simple in nature, I don't think I'm pulling a million rows of data, maybe but doubt it.  So I run report ABC and I see blocking issues in SQL Server Enterprise Mgr.  If I run report XYZ that isn't too much different than ABC, I do not see blocking issues.  Hmm, what could be different?  In SQL-Mgr when I look at the SPID info generated by the report I can see the tables the report is referencing and below is what I discovered.
    The one difference I see is under the "Index" column - the report blocking shows "XPKcall_req" where call_req is the table I'm pulling from.  The report that IS NOT blocking shows call_req_x0.  I checked with our dba and he wasn't sure, other than to say XPK is the primary key index.  Okay, then why is one report hitting the primary key index (whatever that is) and the other isn't?  In Crystal I'm not sure how to tell it to stop doing this, I tried shaking my finger and yelling but like my kids this does little.
    Any ideas, with the report that is?

  • Primary key index not working in a select  statment

    Hi ,
    I'm doing a :
    select *
    from my_table
    where B = v1 and
    A = v2 ;
    where A and B are the primary key of the table, in that table the primary key index is there and the order of the primary key definition is A first and then B.
    While testing this statment in my database the Explain Plan shows that it is using the index ok but when
    runninng in client database it is not using it becasue of the order (i think), is this something configurable that I need to ask to my DBA ?
    The solution I found was to do the select with a hint wich fix the problem , but I'm curious about why is working in my dadabase and not in the client database
    thanks in advance .
    oracle version 11g

    This is the forum for SQL Developer (Not for general SQL/PLSQL questions). Your question would be better asked in the SQL and PL/SQL forum.
    Short answer: The execution plan used will depend on optimizer settings and table/index statistics. For example if the table has very few rows it may not bother using the index.

Maybe you are looking for

  • HT1848 I cannot get my purchased music to my iTunes library even when following instructions!!  Can someone please help?

    I am having problems transferring my downloaded purchased from my iPhone even after following instructions!  Can someone please help!!!??

  • FontExplorer and Quark6.5

    Has anyone used FontExplorer and Quark6.5, Ive installed FontExplorer and it installs in Xtension in Quark6.5 for activation, it says it will be a bit slower than Quark7, However it causes all my quarks users to crash quark and then it corrupts their

  • Message no. O3453 "No additional quantities imported from external applicat

    When I run LQ01, the following message appears Message no. O3453 "No additional quantities imported from external application" Function MB_CREATE_GOODS_MOVEMENT has been called for an HPM material (additional units of measure), but no additional quan

  • Multi-Thread logging with PrintWriter

    Hi, I'm trying to buffer up some log information and flush it out to a log file at the end of servlet. If I do something like following in a servlet where multiple threaded are doing the same thing, would System.out be a bottleneck? I can see that so

  • Issue with ADD NEW ROW button

    Hi, When I click 'ADD NEW ROW ' button, an empty row is getting created as the last but one column. I want the new row should be add at last. (as the last row). The code I am using : Row row = vo.createRow(); vo.last(); vo.insertRow(row); row.setNewR