Unique Constraint on a Table

I want to have a unique constraint on deptno and emp_name in emp table.
What I want is:
Any Dept can have 100 Steves OR 100 Johns but only 1 Robert
Dept No               Emp Name     
10               Steve
10               Steve
10               Robert
20               Steve
20               Robert
20                John
20               John
How can we achieve this with unique constraint??
Cheers
Prasad.

You are talking about unique constraint and you want to have duplicate records in a column with unique constraint. No, what you want is not possible with unique constraint. When you have a unique constraint on emp_name, how can you have 100 johns or 100 steves. Forget about 100, you can't have the second john/steve.

Similar Messages

  • UNIQUE constraint but with a condition?

    Hi!
    Is it possible to define a unique constraint in a table which would apply only under a condition (depending on row content only) ?
    For example:
    CREATE TABLE example
      pk number,
      a number,
      b number,
      c VARCHAR2(10),
      x number
    The constraint would be UNIQUIE (a,b), but only when x is > 10.
    So if x is not above 10, then same values for a nd b should be allowed.
    Maybe with a view ?
    Like this?
    create view example_view  ( unique (a,b)) AS
    select a,b from example where x > 10
    with read only; -- ??? needed? Regards,
    David

    Hello David,
    not on the table directly, but you can define a Materialized View with your condition
    CREATE MATERIALIZED VIEW check_example
       BUILD IMMEDIATE
       REFRESH FAST ON COMMIT
       AS SELECT a,b
       FROM example
       WHERE x > 10On this MV you can define your unique constraint. The refresh will fail if the condition is not met and you will get an error for your changes in the example table..
    Regards
    Marcus

  • Unique constraint not working

    Hi,
    I originally had a unique constraint on a table on columns say C1,C2,C3. Later I added a 4th column C4. I can see that the 4th column is part of the same index in all_cons_columns.r
    But, when I try to insert row with same value of C1,C2,C3 but different C4 it gives me the same Unique key error even though the value I am entering for C4 is unique for that table. What could cause this?

    user13755008 wrote:
    select * from all_cons_columns where constraint_name='HSRP_TRACK_UK';
    OWNER CONSTRAINT_NAME TABLE_NAME
    COLUMN_NAME
    POSITION
    NC3 HSRP_TRACK_UK HSRP_TRACK
    ODBID_EQP
    1
    NC3 HSRP_TRACK_UK HSRP_TRACK
    START_DATE
    4
    NC3 HSRP_TRACK_UK HSRP_TRACK
    OBJECT_NUM
    2
    NC3 HSRP_TRACK_UK HSRP_TRACK
    did some details get misplaced here?
    >
    >
    >
    select * from all_ind_columns where INDEX_NAME='HSRP_OBJ_INTER_ST_UIX';
    INDEX_OWNER INDEX_NAME TABLE_OWNER TABLE_NAME
    COLUMN_NAME
    COLUMN_POSITION COLUMN_LENGTH CHAR_LENGTH DESC
    NC3 HSRP_OBJ_INTER_ST_UIX NC3 HSRP_TRACK
    ODBID_EQP
    1 22 0 ASC
    NC3 HSRP_OBJ_INTER_ST_UIX NC3 HSRP_TRACK
    OBJECT_NUM
    2 4 4 ASC
    NC3 HSRP_OBJ_INTER_ST_UIX NC3 HSRP_TRACK
    INTERFACE
    3 32 32 ASC
    NC3 HSRP_OBJ_INTER_ST_UIX NC3 HSRP_TRACK
    START_DATE
    4 7 0 ASC
    select * from nc3.hsrp_track where odbid= 87820678;
    ODBID CREATETMSTMP CREATEUS CREATETRAN
    LASTUPDTMSTMP LASTUPDU LASTUPDTRAN ODBID_EQP
    ODBID_START_ORDER ODBID_STOP_ORDER ODBID_PREV START_DATE STOP_DATE STATUS COMPONENT_TYPE OBJE
    INTERFACE PROCESS
    87820678 2013-01-18-11:29:29.285050 NC3USER StoreRouting
    2013-01-18-11:29:29.285050 NC3USER StoreRouting 87811116
    87811106 2013-01-18 9999-12-31 Started Equipment 1
    Serial0/0 line-protocol
    SQL> insert into NC3.HSRP_TRACK Values(3,'2013-01-18-11:29:29.436033', 'NC3USER ', 'StoreRouting', '2013-01-18-11:29:29.436033', 'NC3USER ', 'StoreRouting ', 87820377,'','','', '2013-01-18','9999-12-31','Started', 'Equipment', '1', 'Serial0/0', '');
    insert into NC3.HSRP_TRACK Values(3,'2013-01-18-11:29:29.436033', 'NC3USER ', 'StoreRouting', '2013-01-18-11:29:29.436033', 'NC3USER ', 'StoreRouting ', 87820377,'','','', '2013-01-18','9999-12-31','Started', 'Equipment', '1', 'Serial0/0', '')
    ERROR at line 1:
    ORA-00001: unique constraint (NC3.HSRP_TRACK_UK) violated
    SQL> desc nc3.hsrp_track
    Name Null? Type
    ODBID NOT NULL NUMBER(11)
    CREATETMSTMP NOT NULL TIMESTAMP(6)
    CREATEUSER NOT NULL CHAR(8)
    CREATETRAN NOT NULL CHAR(16)
    LASTUPDTMSTMP NOT NULL TIMESTAMP(6)
    LASTUPDUSER NOT NULL CHAR(8)
    LASTUPDTRAN NOT NULL CHAR(16)
    ODBID_EQP NOT NULL NUMBER(11)
    ODBID_START_ORDER NUMBER(11)
    ODBID_STOP_ORDER NUMBER(11)
    ODBID_PREV NUMBER(11)
    START_DATE NOT NULL DATE
    STOP_DATE NOT NULL DATE
    STATUS NOT NULL CHAR(16)
    COMPONENT_TYPE NOT NULL VARCHAR2(32)
    OBJECT_NUM NOT NULL VARCHAR2(4)
    INTERFACE NOT NULL VARCHAR2(32)
    PROCESS VARCHAR2(15)
    SQL> select * from nc3.hsrp_track where odbid_eqp=87820377;
    no rows selected
    Please, see since odbid_eqp that I am trying to insert is not presen in table unique index should not be thrown in any case? I am confused.
    Edited by: user13755008 on Jan 18, 2013 8:24 PMpost results from SQL below
    SELECT COLUMN_NAME, POSITION, CONSTRAINT_NAME FROM ALL_CONS_COLUMNS
    WHERE TABLE_NAME = 'HSRP_TRACK' AND OWNER = 'NC3';

  • Add a unique constraint on binary XML table

    How add a unique constraint of "brevet" field?
    The following INSERT failed
    SQL Error: ORA-19025: EXTRACTVALUE renvoie la valeur d'un seul noeud
    19025. 00000 - "EXTRACTVALUE returns value of only one node"
    If the ALTER is made after the INSERT is done, INSERT is valid but ALTER failed with the same error message!
    /* copy the file compavions.xml
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <compagnie>
         <comp>AB</comp>
         <flotte>
              <avion immat="F-WTSS" capacite="90">
                   <typeAv>Concorde</typeAv>
              </avion>
              <avion immat="F-GFDR" capacite="145">
                   <typeAv>A320</typeAv>
              </avion>
              <avion immat="F-GTYA" capacite="150">
                   <typeAv>A320</typeAv>
              </avion>
         </flotte>
         <nomComp>Air Blagnac</nomComp>
         <pilotes>
              <pilote>
              <brevet>PL-1</brevet>
              <nom>C. Sigaudes</nom>
              </pilote>
              <pilote>
              <brevet>PL-2</brevet>
              <nom>P. Filloux</nom>
              </pilote>
         </pilotes>
    </compagnie>
    in C:\...
    --DROP DIRECTORY repxml;
    --CREATE DIRECTORY repxml AS 'C:\...';
    DROP TABLE pilote_binary_xml5;
    CREATE TABLE pilote_binary_xml5 OF XMLType
    XMLTYPE STORE AS BINARY XML
    VIRTUAL COLUMNS
    (col AS (EXTRACTVALUE(OBJECT_VALUE, '/compagnie/pilotes/pilote/brevet')));
    ALTER TABLE pilote_binary_xml5 ADD CONSTRAINT brevet_unique UNIQUE (col);
    INSERT INTO pilote_binary_xml5 VALUES (XMLType(BFILENAME ('REPXML','compavions.xml'), NLS_CHARSET_ID ('AL32UTF8')));
    --ALTER TABLE pilote_binary_xml5 ADD CONSTRAINT brevet_unique UNIQUE (col);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    You could try something like
    (extract(OBJECT_VALUE,compagnie/pilotes/pilote/brevet').getStringVal());
    but this is probably unadvisable.
    I suggest an alternative is for you to look at XMLINDEX so that you can bring the 'proper' XML functions into play like XMLTABLE etc.

  • What is the best practice for inserting (unique) rows into a table containing key columns constraint where source may contain duplicate (already existing) rows?

    My final data table contains a two key columns unique key constraint.  I insert data into this table from a daily capture table (which also contains the two columns that make up the key in the final data table but are not constrained
    (not unique) in the daily capture table).  I don't want to insert rows from daily capture which already exists in final data table (based on the two key columns).  Currently, what I do is to select * into a #temp table from the join
    of daily capture and final data tables on these two key columns.  Then I delete the rows in the daily capture table which match the #temp table.  Then I insert the remaining rows from daily capture into the final data table. 
    Would it be possible to simplify this process by using an Instead Of trigger in the final table and just insert directly from the daily capture table?  How would this look?
    What is the best practice for inserting unique (new) rows and ignoring duplicate rows (rows that already exist in both the daily capture and final data tables) in my particular operation?
    Rich P

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> My final data table contains a two key columns unique key constraint. [unh? one two-column key or two one column keys? Sure wish you posted DDL] I insert data into this table from a daily capture table (which also contains the two columns that make
    up the key in the final data table but are not constrained (not unique) in the daily capture table). <<
    Then the "capture table" is not a table at all! Remember the fist day of your RDBMS class? A table has to have a key.  You need to fix this error. What ETL tool do you use? 
    >> I don't want to insert rows from daily capture which already exists in final data table (based on the two key columns). <<
    MERGE statement; Google it. And do not use temp tables. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Insert result of query into a table with unique constraint

    Hi,
    I have a query result that I would like to store in a table. The target table has a unique constraint. In MySQL you can do
    insert IGNORE into myResultTable <...select statement...>
    The IGNORE clause means if inserting a row would violate a unique or primary key constraint, do not insert the row, but continue inserting the rest of the query. Leaving the IGNORE clause out would cause the insert to fail and an error to return.
    I would like to do this in oracle... that is insert the results of a query that are not already in the target table. What is the best way to do this? One way is use a procedural language and loop through the first query, checking to see if each row is a duplicate before inserting it. I would think this would be slow if there are lots of records. Other options...
    insert into myTargetTable
    select value from mySourceTable where ... and not exists (select 'x' from myTargetTable where value = mySourceTable.value)
    insert into myTargetTable
    select mySourceTable.value
    from myTargetTable RIGHT JOIN mySourceTable
    ON myTargetTable.value = mySourceTable.value
    where ...
    and myTargetTable.value IS NULL
    any other suggestions?
    Thanks,
    Simon

    Try doing a MINUS instead of not exists., ie Source MINUS Target.
    Disabling the constraint will not help you since this will allow the duplicate rows to be inserted into the table. I don't think you want this.
    --kalpana                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Adding a UNIQUE Constraint to an existing table

    Hi,
    I got this issue because of the existing data. My issue is in my table I want to add a unique constraint to two columns but i cannot add this becuase of the existing repeating data. And I cannot do a data repair to fix the repeating data since the customer is reling on this data so we can not get the decision to repair the data.
    As a solution I try this method, by adding a function to check the repeating data before inserting the data to the table. It's working fine to a user but when it come to multiple users it's not working because users can log to the database and can do their transactions simultaneously.
    My question is; is there a way in oracle to add a constraint to the data that can add in future not to the old existing data?
    Thanks,
    Darex.

    user9359353 wrote:
    Hi,
    As a solution I try this method, by adding a function to check the repeating data before inserting the data to the table. It's working fine to a user but when it come to multiple users it's not working because users can log to the database and can do their transactions simultaneously.
    show us what is "not working". if you are calling this function from a trigger the correct way, the first person to commit will have their data inserted and the next person will not be able to insert.
    edit: you may want to have a read through this thread: where I was encountering a problem with multi-row validation using triggers:
    Row level validation dependant on other rows?
    note this post:
    Rob van Wijk wrote:
    Hi WhiteHat,
    Here are two blogposts of mine about this subject that you might find useful.
    One with some guidelines about implementing entity rules: http://rwijk.blogspot.com/2008/08/implementing-entity->rules.html
    And one with an example how to implement (among others) an overlap check in the context of another option for your >question, the product RuleGen: http://rwijk.blogspot.com/2008/05/rulegen-test.html
    Hope this helps.
    Regards,
    Rob.Edited by: WhiteHat on Jun 8, 2011 3:51 PM

  • Table with unique Constraint

    Dear All
    i have a a project ADF-BC / JSF - JDeveloper 11.1.2.3.0 latest, and i have EO contains PK constrain in db in 2 fields (userid & Roleid) and i implemented bundle to handle error message with jbo error code and it works fine in AM test
    and i have VO contains LOV in one attribute of this unique constrain columns (Roleid), now i dropped VO in jsf page as a af:table as below with input text with list of values for roleid and auto submit = true , and i face unexpected behavior from lov attribute in case of entering repeated value ..
    when i enter another repeated value , it give me error message i created in the bundle and everything ok until now
    but when i tab out of input text with list of values , it go back to old value as may be validation fired in back ground , it is not a problem until now
    when i try to make anything else, he still gives me error message of duplicated key
    i change the value again to correct value to avoid duplication error message , i am surprised , still i get the error message and shows me the repeated value again !!
    simply it still save the old repeated value however i corrected , please any one help me to know what is happening and how to solve ?
    Attribute in EO :
    <Attribute
    Name="RoleId"
    Precision="10"
    ColumnName="ROLE_ID"
    SQLType="VARCHAR"
    Type="java.lang.String"
    ColumnType="VARCHAR2"
    TableName="USER_ROLES"
    PrimaryKey="true">
    <DesignTime>
    <Attr Name="_DisplaySize" Value="10"/>
    </DesignTime>
    <validation:ExistsValidationBean
    Name="RoleId_Rule_1"
    ResId="CS.model.BC.EO.UserRolesEO.RoleId_Rule_1"
    OperandType="EO"
    AssocName="CS.model.BC.ASS.UsersRolesFk2ASS"/>
    </Attribute>
    Interface af : table
    <af:table value="#{bindings.UserRoles2.collectionModel}" var="row"
    rows="#{bindings.UserRoles2.rangeSize}"
    emptyText="#{bindings.UserRoles2.viewable ? 'No data to display.' : 'Access Denied.'}"
    fetchSize="#{bindings.UserRoles2.rangeSize}"
    rowBandingInterval="0"
    filterModel="#{bindings.UserRoles2Query.queryDescriptor}"
    queryListener="#{bindings.UserRoles2Query.processQuery}"
    filterVisible="true" varStatus="vs"
    selectedRowKeys="#{bindings.UserRoles2.collectionModel.selectedRow}"
    selectionListener="#{bindings.UserRoles2.collectionModel.makeCurrent}"
    rowSelection="single" id="t1" columnSelection="none"
    columnStretching="column:c3">
    <af:column sortProperty="#{bindings.UserRoles2.hints.RoleId.name}"
    filterable="true" sortable="true"
    headerText="#{bindings.UserRoles2.hints.RoleId.label}"
    id="c2">
    <af:inputListOfValues id="roleIdId"
    popupTitle="Search and Select: #{bindings.UserRoles2.hints.RoleId.label}"
    value="#{row.bindings.RoleId.inputValue}"
    model="#{row.bindings.RoleId.listOfValuesModel}"
    required="#{bindings.UserRoles2.hints.RoleId.mandatory}"
    columns="#{bindings.UserRoles2.hints.RoleId.displayWidth}"
    shortDesc="#{bindings.UserRoles2.hints.RoleId.tooltip}"
    autoSubmit="true" editMode="select">
    <f:validator binding="#{row.bindings.RoleId.validator}"/>
    </af:inputListOfValues>
    </af:column>
    <af:column sortProperty="#{bindings.UserRoles2.hints.RoleName.name}"
    sortable="true"
    headerText="#{bindings.UserRoles2.hints.RoleName.label}"
    id="c3">
    <af:outputFormatted value="#{row.bindings.RoleName.inputValue}"
    id="of7" partialTriggers="roleIdId"/>
    </af:column>
    <af:column sortProperty="#{bindings.UserRoles2.hints.Active.name}"
    filterable="true" sortable="true"
    headerText="#{bindings.UserRoles2.hints.Active.label}"
    id="c4">
    <af:outputFormatted value="#{row.bindings.Active.inputValue}"
    id="of8" partialTriggers="roleIdId"/>
    </af:column>
    </af:table>
    Edited by: user8854969 on Oct 7, 2012 1:34 PM
    Edited by: user8854969 on Oct 7, 2012 2:16 PM

    I believe there is a little confusion here. The error I am encountering has to do with a unique constraint violation and not a foreign key constraint. If I have the data:
    PK FK sequence
    1 5 1
    2 5 2
    3 5 3
    with a unique constraint on (FK, sequence) and want to change it to:
    PK FK sequence
    1 5 1
    4 5 2 --insert
    2 5 3 --update on sequence
    3 5 4 --update on sequence
    I am currently getting a unique constraint violation because the insert is issued before the updates, and the updates alone cause problems because they are issued out of order (i.e. if I do the shifting operation without the insertion of a new record).

  • Unique constraint violation on version enabled table

    hi!
    we're facing a strange problem with a version enabled table that has an unique constraint on one column. if we rename an object stored in the table (the name-attribute of the object is the one that has a unique constraint on the respective column) and rename it back to the old name again, we get an ORA-00001 unique constraint violation on the execution of an update trigger.
    if the constraint is simply applied as before to the now version enabled table, I understand that this happens, but shouldn't workspace manager take care of something like that when a table with unique constraints is version enabled? (the documentation also says that) because taking versioning into account it's not that we try to insert another object with the same name, it's the same object at another point in time now getting back it's old name.
    we somewhat assume that to be a pretty standard scenario when using versioned data.
    is this some kind of bug or do we just miss something important here?
    more information:
    - versioning is enabled on all tables with VIEW_WO_OVERWRITE and no valid time support
    - database version is 10.2.0.1.0
    - wm installation output:
    ALLOW_CAPTURE_EVENTS OFF
    ALLOW_MULTI_PARENT_WORKSPACES OFF
    ALLOW_NESTED_TABLE_COLUMNS OFF
    CR_WORKSPACE_MODE OPTIMISTIC_LOCKING
    FIRE_TRIGGERS_FOR_NONDML_EVENTS ON
    NONCR_WORKSPACE_MODE OPTIMISTIC_LOCKING
    NUMBER_OF_COMPRESS_BATCHES 50
    OWM_VERSION 10.2.0.1.0
    UNDO_SPACE UNLIMITED
    USE_TIMESTAMP_TYPE_FOR_HISTORY ON
    - all operations are done on LIVE workspace
    any help is appreciated.
    EDIT: we found out the following: the table we are talking about is the only table where the unique constraint is left. so there must have been a problem during version enabling. on another oracle installation we did everything the same way and the unique constraint wasn't left there, so everything works fine.
    regards,
    Andreas Schilling
    Message was edited by:
    aschilling

    hi!
    we're facing a strange problem with a version enabled table that has an unique constraint on one column. if we rename an object stored in the table (the name-attribute of the object is the one that has a unique constraint on the respective column) and rename it back to the old name again, we get an ORA-00001 unique constraint violation on the execution of an update trigger.
    if the constraint is simply applied as before to the now version enabled table, I understand that this happens, but shouldn't workspace manager take care of something like that when a table with unique constraints is version enabled? (the documentation also says that) because taking versioning into account it's not that we try to insert another object with the same name, it's the same object at another point in time now getting back it's old name.
    we somewhat assume that to be a pretty standard scenario when using versioned data.
    is this some kind of bug or do we just miss something important here?
    more information:
    - versioning is enabled on all tables with VIEW_WO_OVERWRITE and no valid time support
    - database version is 10.2.0.1.0
    - wm installation output:
    ALLOW_CAPTURE_EVENTS OFF
    ALLOW_MULTI_PARENT_WORKSPACES OFF
    ALLOW_NESTED_TABLE_COLUMNS OFF
    CR_WORKSPACE_MODE OPTIMISTIC_LOCKING
    FIRE_TRIGGERS_FOR_NONDML_EVENTS ON
    NONCR_WORKSPACE_MODE OPTIMISTIC_LOCKING
    NUMBER_OF_COMPRESS_BATCHES 50
    OWM_VERSION 10.2.0.1.0
    UNDO_SPACE UNLIMITED
    USE_TIMESTAMP_TYPE_FOR_HISTORY ON
    - all operations are done on LIVE workspace
    any help is appreciated.
    EDIT: we found out the following: the table we are talking about is the only table where the unique constraint is left. so there must have been a problem during version enabling. on another oracle installation we did everything the same way and the unique constraint wasn't left there, so everything works fine.
    regards,
    Andreas Schilling
    Message was edited by:
    aschilling

  • Create unique constraint on table

    Hello experts,
    Is it possible to define a unique constraint on table fields that aren't part of the primary key?
    Thank you in advance.

    One way is to create an index on the field and make it unique (SE11->GOTO->Indexes). Then in your programs Inserts, Appends and Updates would fail giving you a non zero SY-SUBRC when a program tries to enter a value that already exists.
    Don't forget to include MANDT in the index otherwise you'll end up with uniqueness across all clients

  • Unique Constraint Not Allowed in OA Table design?

    Is it really true or is just my OApps Admin /DBA is just plain stupid for not allowing unique constraint at table level?
    I have to implement a EO attribute level validation that does a select on an unindexed field thru the List Validator feature.
    The problem is it is taking 40-60 seconds to commit something to the EO.

    Thats true, if talking about only OAF, you don't need the constraint as you can handle that in code!
    --Mukul                                                                                                                                                                                                                                                       

  • Bulk table update returning ORA-00001: unique constraint

    I'm trying to update every record in a PROPERTY table that has a CLASS of either 1 or 9 and a STATUS of 'LHLD'. CLASS and STATUS descriptor records are in different tables to the PROPERTY table but reference the PROPERTY records by the PROPERTY tables unid.
    I have wrote the following update command,
    UPDATE RNT_PROPERTY_DESCRIPTOR SET DESCRIPTOR = 'PROP', DESCRIPTOR_VALUE = '1', EFFECT_DATE = '01-APR-04', USER_ID = 'USER'
    WHERE RNT_PROPERTY_DESCRIPTOR.UNID IN (SELECT PROPERTY.UNID FROM PROPERTY, PROPERTY_CLASS_STATUS
    WHERE PROPERTY_CLASS_STATUS.PROP_CLASS = '1'
    OR PROPERTY_CLASS_STATUS .PROP_CLASS = '9'
    AND PROPERTY.UNID IN (SELECT PROPERTY.UNID FROM PROPERTY, PROP_STATUS_HIST
    WHERE PROP_STATUS_HIST.code = 'LHLD'));
    However, after executing for around 10 mins the process update fails and the following error is returned:
    ORA-00001: unique constraint (RNT_PROPERTY_DESCRIPTOR_IDX) violated
    I know that the IDX suffix refers to the table INDEX but I'm not sure why I'm getting a key constraint, none of the colums that I'm trying to update must be unique.
    For info the PROPERTY table has around 250,000 rows.
    Any ideas? Is there an error in my update statement?
    Thanks in advance.

    Gintsp,
    can you explain a little more? I'm not sure what you are suggesting that I try.
    Here is the output of what I have tried
    SQL> UPDATE RNT_PROPERTY_DESCRIPTOR SET DESCRIPTOR = 'PROP', DESCRIPTOR_VALUE = '1', EFFECT_DATE = '01-APR-04', USER_ID = 'USER'
    2 WHERE RNT_PROPERTY_DESCRIPTOR.UNID IN (SELECT PROPERTY.UNID FROM PROPERTY, PROPERTY_CLASS_STATUS
    3 WHERE PROPERTY_CLASS_STATUS.PROP_CLASS = '1'
    4 OR PROPERTY_CLASS_STATUS.PROP_CLASS = '9'
    5 AND PROPERTY.UNID IN (SELECT PROPERTY.UNID FROM PROPERTY, PROP_STATUS_HIST
    6 WHERE PROP_STATUS_HIST.CODE = 'LHLD'));
    UPDATE RNT_PROPERTY_DESCRIPTOR SET DESCRIPTOR = 'PROP', DESCRIPTOR_VALUE = '1', EFFECT_DATE = '
    ERROR at line 1:
    ORA-00001: unique constraint (RNT_PROPERTY_DESCRIPTOR_IDX) violated
    SQL> select owner, constraint_type, table_name, search_condition from user_constraints where constraint_name = 'RNT_PROPERTY_DESCRIPTOR_IDX';
    no rows selected
    The RNT_PROPERTY_DESCRIPTOR table structure is as follows:
    Name Null? Type
    UPRN NOT NULL NUMBER(7)
    DESCRIPTOR NOT NULL VARCHAR2(4)
    DESCRIPTOR_VALUE VARCHAR2(11)
    EFFECT_DATE NOT NULL DATE
    VALUE_DESCRIPTION VARCHAR2(35)
    POINTS NUMBER(2)
    POUNDS NUMBER(5,2)
    SUPERSEDED VARCHAR2(1)
    CURRENT_FLAG VARCHAR2(1)
    FUTURE VARCHAR2(1)
    END_EFFECT_DATE DATE
    USER_ID NOT NULL VARCHAR2(10)
    CREATE_DATE DATE
    -------------------------------------------------------------

  • Difference between unique constraint and unique index

    1. What is the difference between unique constraint and unique index when unique constraint is always indexed ? Which one is better in this case for better performance ?
    2. Is Composite index of 3 columns x,y,z better
    or having independent/ seperate indexes on 3 columns x,y,z is better for better performance ?
    3. It has been very confusing for me to decide which columns to index, I have indexed most foreignkey columns, is it a good idea ? We do lot of selects and DMLS on most of our tables. Is there any query that I can run and find out if indexes are really being used and if they are improving any performance. I have analyzed and computed my indexes using ANALYZE index index_name validate structure and COMPUTE STATISTICS;
    null

    1. Unique index is part of unique constraint. Of course you can create standalone unique index. But is is no point to skip the logical view of business if you spend same effort to achive.
    You create unique const. Oracle create the unique index for you. You may specify index characteristic in unique constraint.
    2. Depends. You can't utilize the composite index if the searching condition is not whole or front part of the indexing key. You can't utilize your index if you query the table for y=2. That is.
    3. As old words in database arena, Index may be good or bad for a table depending on the size of table, number of columns in the table... etc. It is very environmental dependent. In fact, It is part of database nomalization. Statistic is a way oracle use to determine the execution plan.
    Steve
    null

  • Unique Index vs. Unique Constraint

    Hi All,
    I'm studying for the Oracle SQL Expert Certification. At one point in the book, while talking about indices, the author says that a unique index is not the same a unique constraint. However, he doesn't explain why they're two different things.
    Could anyone clarify the difference between the two, please?
    Thanks a lot,
    Valerio

    A constraint has different meaning to an index. It gives the optimiser more information and allows you to have foreign keys on the column, whereas a unique index doesn't.
    eg:
    SQL> create table t1 (col1 number, col2 varchar2(20), constraint t1_uq unique (col1));
    Table created.
    SQL> create table t2 (col1 number, col2 varchar2(20));
    Table created.
    SQL> create unique index t2_idx on t2 (col1);
    Index created.
    SQL> create table t3 (col1 number, col2 number, col3 varchar2(20), constraint t3_fk
      2                   foreign key (col2) references t1 (col1));
    Table created.
    SQL> create table t4 (col1 number, col2 number, col3 varchar2(20), constraint t4_fk
      2                   foreign key (col2) references t2 (col1));
                     foreign key (col2) references t2 (col1))
    ERROR at line 2:
    ORA-02270: no matching unique or primary key for this column-listIt's like saying "What's the difference between a car seat and an armchair? They both allow you to sit down!"

  • ORA-00001: unique constraint

    Hi,
    I disabled the primary key of the table to which I insert the data like this :
    INSERT INTO TABLE_X
    select * from table_1 UNION ALL
    select * from table_2 ;
    but I receive this error :
    ORA-00001: unique constraint TABLE_X.PK violated
    Why ? It is already disabled.
    thank you.
    Message was edited by:
    user522961
    Message was edited by:
    user522961
    Message was edited by:
    user522961

    Is it possible you kept the index when disabling the primary key?
    YAS@11G>create table t as select object_id from all_objects where rownum<=10;
    Table created.
    YAS@11G>alter table t add constraint PK_T primary key(object_id);
    Table altered.
    YAS@11G>alter table t disable constraint pk_t;
    Table altered.
    YAS@11G>insert into t select * from t;
    10 rows created.
    YAS@11G>rollback;
    Rollback complete.
    YAS@11G>alter table t enable constraint pk_t;
    Table altered.
    YAS@11G>alter table t disable constraint pk_t keep index;
    Table altered.
    YAS@11G>insert into t select * from t;
    insert into t select * from t
    ERROR at line 1:
    ORA-00001: unique constraint (YAS.PK_T) violated

Maybe you are looking for

  • How to install OS X in a 500gb HDD on a A1181 maccbook

    I have an old A1181 maccbok (13 inch late 2006) whitch hdd (120gb) crashed. I bought a brand new Toshiba MA01ADV050 hdd (500gb) that I want to replaced the crashed one. Is it possible? I have replaced the drive but when I start the machine pressing t

  • How do I create "How to" files in Lightroom similar to Photoshop CS3

    Hi I've run a search in the forums and the like but haven't been able to come up with any thing. I watched and tried out Matt Klowkowskis' "Printing multiple photos in multiple sizes using picture package". What I want to do is make a "help file" in

  • Can you connect the Apple TV to a Harmon Kardon receiver?

    I have all my sound running through the harmon kardon receiver. I just don't know how I would connect it. would I put it through the input or output?

  • MagSafe so so

    MagSafe 1 60W A1344 is not working, then I let it seat for a while and it works again then fails again, then works again?

  • Locale Builder Utility

    Hi, I am trying to build a locale in URDU Language. I also heard about LOCALE BUILDER UTILITY. So, i am planning to build my urdu-locale using LOCALE BUILDER Utility.. So, Is it possible to build my URDU Locale using LOCALE Builder Utility??? Plz rep