Add a foriegn key constraint to to a sub type on an object table

Hi,
I'm trying to set up a new table of an object type in our DB at work and on it I want to create a foreign key constraint on one of the attributes of one of the sub types
The table is called documents and is a table of document_ot
Definition:
create or replace
TYPE document_ot AS OBJECT (
-- ATTRIBUTES
created_date DATE,
created_by VARCHAR2( 32 ),
doc_id NUMBER,
-- CONSTRUCTORS
) NOT INSTANTIABLE NOT FINAL;
This type is extended by the type funding_certificates_ot
create or replace
TYPE funding_certificate_ot UNDER document_ot (
-- ATTRIBUTES
fc_prefix VARCHAR2( 2 ),
fc_sequence NUMBER,
fc_suffix VARCHAR2( 1 ),
fc_pr_id NUMBER,
-- CONSTRUCTORS
-- METHODS
) NOT FINAL;
I want to add a constraint to the to documents table that says that the funding_certificate_ot column fc_pr_id references pr_id in the table payruns.
I've managed to create an index on the fc_pr_id column using:
CREATE INDEX fc_pr_idx
ON documents d (treat (value(d) as funding_certificate_ot).fc_pr_id);
The code I thought I'd use for the foreign key constraint would be:
ALTER TABLE documents d
ADD CONSTRAINT doc_pr_fk FOREIGN KEY
treat (value(d) as funding_certificate_ot).fc_pr_id
REFERENCES payruns
(pr_id)
ENABLE;
But that doesn't work - would someone be able to give me the correct syntax please?
Many thanks

Hi,
I'm trying to set up a new table of an object type in our DB at work and on it I want to create a foreign key constraint on one of the attributes of one of the sub types
The table is called documents and is a table of document_ot
Definition:
create or replace
TYPE document_ot AS OBJECT (
-- ATTRIBUTES
created_date DATE,
created_by VARCHAR2( 32 ),
doc_id NUMBER,
-- CONSTRUCTORS
) NOT INSTANTIABLE NOT FINAL;
This type is extended by the type funding_certificates_ot
create or replace
TYPE funding_certificate_ot UNDER document_ot (
-- ATTRIBUTES
fc_prefix VARCHAR2( 2 ),
fc_sequence NUMBER,
fc_suffix VARCHAR2( 1 ),
fc_pr_id NUMBER,
-- CONSTRUCTORS
-- METHODS
) NOT FINAL;
I want to add a constraint to the to documents table that says that the funding_certificate_ot column fc_pr_id references pr_id in the table payruns.
I've managed to create an index on the fc_pr_id column using:
CREATE INDEX fc_pr_idx
ON documents d (treat (value(d) as funding_certificate_ot).fc_pr_id);
The code I thought I'd use for the foreign key constraint would be:
ALTER TABLE documents d
ADD CONSTRAINT doc_pr_fk FOREIGN KEY
treat (value(d) as funding_certificate_ot).fc_pr_id
REFERENCES payruns
(pr_id)
ENABLE;
But that doesn't work - would someone be able to give me the correct syntax please?
Many thanks

Similar Messages

  • Join 2 tables which are not related with any primary-foriegn key constraint

    Hello,
    How to join 2 tables which are not related with any primary key foreign key constraint.
    Ex.Consider Table A has 5 columns->A_ID,A_Name,A_Address,A_City,A_Pin(Total 10 rows)
    Table B has 5 columns->B_ID,B_Name,B_Adress,B_City,B_City(Total 30 rows)
    From both the table i want the data,which i need to use in curosr to display finally as "Address Label".
    Both the table are entirely different,but there can be some names of Table A which may come in Table B also,if the name,address and city is also same.That means same person in both the table.
    So finally i want total number of distinct records(distinct data of Table A which is not in B+all the data of table B) to come under Address Label.
    How can i write the select query for this condition?
    Thanks
    Swapna

    Hi, Swapna,
    user11018268 wrote:
    Hello,
    How to join 2 tables which are not related with any primary key foreign key constraint.
    Ex.Consider Table A has 5 columns->A_ID,A_Name,A_Address,A_City,A_Pin(Total 10 rows)
    Table B has 5 columns->B_ID,B_Name,B_Adress,B_City,B_City(Total 30 rows)
    Both the table are entirely different,but there can be some names of Table A which may come in Table B also,if the name,address and city is also same.That means same person in both the table.I think you want a UNION, not a join.
    If you have 10 rows in table_a, and 30 rows in table_b, then
    SELECT       A_ID,          A_Name,     A_Address,     A_City,     A_Pin
    FROM      table_a
    UNION
    SELECT       B_ID,          B_Name,     B_Adress,     B_City,     B_City
    FROM      table_b
    ORDER BY            2,               4          
    ;will produce up to 40 rows; 40 if there are no duplicates. (UNION implies DISTINCT.)
    The corresponding column types should be similar, if not exactly the same.
    There's no problem if A_Name is VARCHAR2 (50) and B_Name is CHAR (30).
    However, there will be a problem if A_ID is a NUMBER and B_ID is a TIMESTAMP.
    You must have the same number of columns in all branches of the UNION.
    If you want an ORDER BY clause, put it at the very end, after the last branch of the UNION.
    You can use positional notation (where 2 means the 2nd column) like I did, or you can use names from the first prong of the UNION (such as A_Name).
    From both the table i want the data,which i need to use in curosr to display finally as "Address Label".
    So finally i want total number of distinct records(distinct data of Table A which is not in B+all the data of table B) to come under Address Label.I'm not sure what your mean about "Address Label".
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables, and the exact results (formatted) that you want from that data.
    You can concatenate all 5 columns into one VARCHAR2 column, if you want to.
    You'll probably want to use RPAD (or simillar functions) to make the output line up nicely.
    If any of the columns are not strings, use TO_CHAR to make string versions of them.
    For example:
    SELECT  TO_CHAR (A_ID, '9999999')
         || '   '          -- leave a little space between the left-justified a_id and the right-justified a_name
         || RPAD (A_Name, 25)
         || RPAD (A_Address, 50)
         ...Edited by: Frank Kulash on Nov 14, 2009 10:11 AM

  • SM30 - Deleting a record with Foriegn Key Constraints

    I have a two custom tables ZCCED_STATUS and ZCCED_COSTITEM. 
    ZCCED_COSTITEM has a status column with a foriegn key to a (PK) status record in ZCCED_STATUS.
    I have generated table maintenance objects for the table ZCCED_STATUS.
    When I go to SM30 and maintain the table ZCCED_STATUS I can select a status record and delete it. (still ZCCED_COSTITEM records using that status)
    Is there any way that SM30 can warn or stop a user from deleting a ZCCED_STATUS record when there are child records in the ZCCED_COSTITEM table?
    Regards,

    Create a maintenance view , link both tables and generate a table maintenance for the maintenance view . it will work.

  • Trouble adding foriegn keys

    I am trying to add a foriegn key to a table through the wizard in the sql server diagram tools. I select the foriegn key table which is film_actors_lookup. The film_actors_lookup table has 2 fields: ActorID and FilmID. Both are primary keys for the film_actors_lookup
    table. The Film table has a FilmID primary key. The Actor table has an ActorID as a primry key. When I go to add a foriegn key relationship between the Actors table and the film_actors_lookup table, I get the error that both tables must
    have the same number of fields. Why is this not working?

    Please post the error message.
    Both ActorID and FilmID needs to be PRIMARY KEY in respective tables.
    You can see it with below script:
    USE [TestDatabase]
    GO
    CREATE TABLE [dbo].[film_actors_lookup] ([FilmID] INT, [ActorID] INT)
    GO
    CREATE TABLE [dbo].[actors] ([ActorID] INT PRIMARY KEY)
    GO
    CREATE TABLE [dbo].[films] ([FilmID] INT PRIMARY KEY)
    GO
    /* Add Foreign Key - ActorID */
    ALTER TABLE [dbo].[film_actors_lookup] ADD CONSTRAINT [FK_Actors_Lookup_Actors_ActorID] FOREIGN KEY ([ActorID]) REFERENCES [dbo].[Actors] ([ActorID])
    GO
    /* Add Foreign Key - FilmID */
    ALTER TABLE [dbo].[film_actors_lookup] ADD CONSTRAINT [FK_Actors_Lookup_Films_FilmID] FOREIGN KEY ([FilmID]) REFERENCES [dbo].[Films] ([FilmID])
    GO
    - Vishal
    SqlAndMe.com

  • Primary Key Constraint

    dear members,
    I have a tables named orders and part. Both of them contain common column named partnum. The column partnum in the table orders contains duplicates. I tried to add a primary key constraint to that column partnum but sql*plus gave me an error unique constraint voilation.
    The reason for the error was because of duplicates in the column partnum but if i want to assign a column as a primary key and suppose it contains duplicates then how can i do that ? I cannot alter my table orders data, in this case how should i proceed further!!!

    You cannot use a single column with duplicates or null values as a primary key. It's that simple.
    If a given single column has duplicates values its not a possible candidate for a primary key. It has to be an unique value.
    I'm not fully sure here but kinda feels like your table "orders" has information about all orders (purchase, sell, whatever) related with "parts". So, this way if its possible that orders has duplicates because you have several orders on the same "part". I think "part" has a primary key on "partnum". If there's a need for a pk in "orders" maybe you have an additional column, let's call it "ordernum".

  • Modifying column adding primary key constraint

    how can we alter a table and modify a column and add a primary key constraint to it??

    987018 wrote:
    can't we add a primary key constraint using the modify command?If the column already exists, and ther is no existing primary key, then
    SQL> create table t (id number, descr varchar2(10));
    Table created.
    SQL> alter table t modify (id not null primary key);
    Table altered.If the column does not yet exist and ther is no primary key then:
    SQL> create table t1 (descr varchar2(10));
    Table created.
    SQL> alter table t1 add (id number not null primary key);
    Table altered.John

  • How add primary key constraint to already existing table with data

    I want apply primary key constraint to already existing table with data
    is there any command or way to do

    Alternatively, assuming you want to ensure uniqueness in your primary key column you can do this:
    alter table <table name> add constraint <cons name> primary key (col1,col2) exceptions into <exception_table>
    If the altter table statement fails this will populate the EXCEPTIONS table with the rows that contain duplicate values for (col1,col2).
    You will need to run (or get a DBA to run) a script called UTLEXCPT.SQL (which will be in the $ORACLE_HOME/rdbms/admin directory) if you don't already have an EXCEPTIONS table.
    Cheers, APC

  • Ora-2270 Error while adding foreign key constraint on top a view

    While adding a constraint, referencing a foreign key column from a view raises error. However, it works fine over a table.
    Here's the sample script:
    create table t_temp (
    sample_id number,
    text varchar2(40))
    alter table t_temp add constraint temp_pk
    primary key (sample_id);
    create view tempvw as select sample_id,text from t_temp;
    create table t_sample (
    uniq_id number,
    sample_id number,
    sample_text varchar(40));
    =========
    ALTER TABLE t_sample ADD CONSTRAINT FK_sample_temp
         FOREIGN KEY (sample_id) REFERENCES t_temp (sample_id);
    This works fine.
    =========
    ==============
    The following raises ERROR....
    ALTER TABLE t_sample ADD CONSTRAINT FK_sample_temp1
         FOREIGN KEY (sample_id) REFERENCES tempvw (sample_id);
    Error starting at line 1 in command:
    ALTER TABLE t_sample ADD CONSTRAINT FK_sample_temp1
         FOREIGN KEY (sample_id) REFERENCES tempvw (sample_id)
    Error report:
    SQL Error: ORA-02270: no matching unique or primary key for this column-list
    02270. 00000 - "no matching unique or primary key for this column-list"
    *Cause:    A REFERENCES clause in a CREATE/ALTER TABLE statement
    gives a column-list for which there is no matching unique or primary
    key constraint in the referenced table.
    *Action:   Find the correct column names using the ALL_CONS_COLUMNS
    catalog view

    What exactly are you trying to accomplish by having a
    referential integrity constraint on a view (which is
    not allowed). PKs and FKs are allowed on views. DISABLE NOVALIDATE is the only allowed state for them. View constraints are used for query rewriting: http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/qradv.htm#sthref1457
    Regards,
    Dima

  • ATG 10.1.1 - MySQL foriegn key issues

    Hi All,
    Am trying to setup ATG 10.1.1 in a distributed environment for development purpose.
    I have 2 boxes.
    Windows box: contains MySQL installation and will be treated as DB Server
    Linux box: contains ATG/Weblogic installation and will be treated as APP Server
    All CIM activities of creating schema and importing data to databases (for CRS) along with all other things completed successfully. BCC/Dynamo Admin are up and running successfully.
    When I try to do full deployment for CRS site in BCC i get following error:
         Error'      Deployment Failed      lpxsku2505_14:price      Sep 18, 2012 1:38:32 PM
    Message Detail:
    CONTAINER:atg.deployment.DistributedDeploymentException; SOURCE:CONTAINER:atg.repository.RepositoryException; SOURCE:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`switchb`.`dcs_price`, CONSTRAINT `dcs_pricpric_lst_f` FOREIGN KEY (`price_list`) REFERENCES `dcs_price_list` (`price_list_id`)) at atg.deployment.repository.RepositoryWorkerThread.processMarkerForAddUpdatePhase(RepositoryWorkerThread.java:273) at atg.deployment.DeploymentWorkerThread.processMarkerPhase(DeploymentWorkerThread.java:562) at atg.deployment.DeploymentWorkerThread.run(DeploymentWorkerThread.java:335)
    Any thoughts? Does ATG 10.1.1 (CRS) even support MySQL?

    HI there,
    I am too getting the same problem. Can you please let me out?
    I have installed ATG 10.1. on Weblogic 10.3.5 with JDK1.6_25 on Windows8.
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production SQL Statement Failed: [++SQLInsert++]
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production INSERT INTO dcs_price(price_id,version,price_list,product_id,sku_id,parent_sku_id,pricing_scheme,list_price)
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production VALUES(?,?,?,?,?,?,?,?)
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production -- Parameters --
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production p[1] = {pd} lpxsku2505_14 (java.lang.String)
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production p[2] = {pd: version} 1 (java.lang.Integer)
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production p[3] = {pd: priceList} plist3130005 (atg.adapter.gsa.SingleValueGSAId)
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production p[4] = {pd: productId} null
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production p[5] = {pd: skuId} xsku2505_14 (java.lang.String)
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production p[6] = {pd: parentSkuId} null
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production p[7] = {pd: pricingScheme} 0 (java.lang.Integer)
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production p[8] = {pd: listPrice} 129.0 (java.lang.Double)
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production [--SQLInsert--]
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`switchingb`.`dcs_price`, CONSTRAINT `dcs_pricpric_lst_f` FOREIGN KEY (`price_list`) REFERENCES `dcs_price_list` (`price_list_id`))
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    **** Error Thu Dec 06 17:47:48 EST 2012 1354834068934 /atg/commerce/pricing/priceLists/PriceLists_production at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

  • How can I run a check for a record across other records in the same dataset based on unique key constraint?

    Dear community,
    I have a flat data set which I run through a lookup and return. I want to check if at least one of the records matching a unique key constraint had a successful return without merging all the records. Can some one point me in the right direction?
    Thanks!
    Marc

    Hi,
    Sounds like a job for the Lookup Check processor!
    As with all check processors, it adds a flag attribute (with a Y/N value) that denotes if the lookup was successful or not, as well as filtering records based on this at output.
    Lookup Check does the same as Lookup and Return but does not return the record(s) looked up.
    Also note that Lookup and Return does not actually merge records, but it does pull back the return data (which you can then split if you want a record for each).
    Regards,
    Mike

  • Publish: dropping index when it is used for foreign key constraint enforcement

    Hi,
    I'm trying to update a target schema from a reference database via Publish. Among the changes to apply, there's an index that needs to be dropped. Since it's linked to a foreign key constraint, it cannot be deleted unless the foreign key is temporarily dropped
    (I saw somewhere that disabling the foreign key should be enough but it doesn't seem to work either).
    Since there are other changes to be made on the same table, this foreign key also has to be dropped before the script can delete the table and re-create it. This part of the script is correctly generated. The problem is that this part appears after the 'DROP
    INDEX' instruction.
    So when generating the update script, SSDT tries to drop the index BEFORE dropping the foreign key. And I can't drop the foreign key in my custom pre-deployment script, otherwise the update script would fail when trying to delete it again.
    Shouldn't SSDT be smart enough to drop the constraint before the index? Is it a bug or did I forget to set an option? If it's not a bug, what can I do apart from doing it manually?
    Thank you for your help

    Hi Elsa,
    That sounds like a bug. Could you please file a Connect issue for this at
    https://connect.microsoft.com/SQLServer/feedback/CreateFeedback.aspx using the category "Developer Tools (SSDT, BIDS, etc.)"? We're trying to track all bugs through
    Connect so that you can tell when we have fixed the issue and we can request more information.
    A workaround for this issue might be to write a pre-deployment script for your project to drop the foreign key prior to deployment. A pre-deployment script can be added to your project by right-clicking on the
    project in solution explorer and then clicking on Add > Script... and selecting Pre-Deployment Script from the list.
    Thanks!

  • Add a primary key to table.

    Hello everybody,
    I want to add a primary key to a table but it doesn't work.
    select count(*), count(id) from tableA;
    COUNT(*) COUNT(ID)
    830447 830447
    You see: The number of ids is equal to the number of rows. The ID is not marked as unique but it should be unique. I try to set id as the primary key:
    alter table tableA add constraint "pk_constraint" PRIMARY KEY (id);
    But I a get an error message: ORA-02437: cannot validate (pk_constraint) - primary key violated.
    What is the problem?
    I use Oracle 11g.

    user9206958 wrote:
    Hello everybody,
    I want to add a primary key to a table but it doesn't work.
    select count(*), count(id) from tableA;
    COUNT(*) COUNT(ID)
    830447 830447
    You see: The number of ids is equal to the number of rows. The ID is not marked as unique but it should be unique. I try to set id as the primary key:
    alter table tableA add constraint "pk_constraint" PRIMARY KEY (id);
    But I a get an error message: ORA-02437: cannot validate (pk_constraint) - primary key violated.
    What is the problem?
    I use Oracle 11g.Revisit your query... 11g can help much in this sql.... select count(*), count(id) from tableA;... to get what your desired output should be.
    Edited by: Z.K. on Mar 30, 2010 1:15 PM

  • IDOC to MSsql,  error in mapping(Violation of PRIMARY KEY constraint)

    Hi All,
    I'm working with MATMAS IDOC  to MSSql. My SQL structure is of 8 tables(multiple statements) with primary key. In mapping i have used UPDATE_INSERT in action field for all the tables but still im getting "Violation of PRIMARY KEY constraint" for the last table structure. first 7 tables are single occurances but the 8th structure data is coming multple times from IDOC(E1MARMM).
    my 8th table structure is :
    STATEMENT8                                IDOC(MAPPED)
    TABLE8
    ACTION                                      UPDATE_INSERT
    TABLE                                           TABLENAME
    ACCESS     0 to Unbounded            MAPPED with E1MARMM
    Item_CD                                used oneasmany +splitbyvalue with MATNR
    Plant_ID                                  used oneasmany +splitbyvalue with WERKS  
    EAN_CAT                                 used oneasmany +splitbyvalue with NUMTP
    EAN                                             used oneasmany +splitbyvalue with EAN11
    Numerator_For_Conversion_To_BaseUOM
    Display_UOM
    Denominator_for_conversion_To_baseUOM
    KEY           0 to Unbounded                 MAPPED with E1MARMM
    Item_CD                                used oneasmany +splitbyvalue with MATNR
    Plant_ID                                  used oneasmany +splitbyvalue with WERKS  
    EAN_CAT                                 used oneasmany +splitbyvalue with NUMTP
    EAN                                             used oneasmany +splitbyvalue with EAN11
    Display_UOM
    in test tab its fine and fetching number of times according to MARMM segments  but in END to END testing its triggering an error stating that
    ""Message processing failed. Cause: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'MM_EAN' (structure 'STATEMENT8'): com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint 'PK_MM_EAN'. Cannot insert duplicate key in object 'dbo.MM_EAN'.  ""
    Plz help me regarding this..

    Hi team,
    How resolve the below error 
    Violation of PRIMARY KEY constraint 'PK_test'. Cannot insert duplicate key in object 'dbo.test'. The duplicate key value is (12610). (Source: MSSQLServer, Error number: 2627) ?
    Thanks,
    Ram
    RAM
    There can be two reasons
    1. The insert script used is having multiple instances of the records with Key as 12610 returned from the source query. If this is the issue add a logic to include only the unique set of id values for records by avoiding duplicates. There are several approaches
    for this like using ROW_NUMBER with PARTITION BY, using a join with derived table etc
    2. The record with Key 12610 already exist in your destination table and your script is again trying to insert another instances of record with same key. This can be avoided by adding a NOT EXISTS condition with a subquery which will check and return only
    those records which doesnt already exist in the source
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Violation of PRIMARY KEY constraint

    Hello,
    I have the following table in my oracle database :
    create table FLTRPTDATA
    esn VARCHAR2(10) default 'ALL' not null,
    periodid NUMBER not null,
    yearid NUMBER default 2007 not null,
    reportid NUMBER not null,
    entryid NUMBER not null,
    operatorid VARCHAR2(30) default 'XXX' not null,
    param1 VARCHAR2(200),
    param2 VARCHAR2(200),
    param3 VARCHAR2(200),
    param4 VARCHAR2(200),
    param5 VARCHAR2(200),
    param6 VARCHAR2(200),
    param7 VARCHAR2(200),
    param8 VARCHAR2(200),
    param9 VARCHAR2(200),
    param10 VARCHAR2(200),
    acid VARCHAR2(8) default 'ALL' not null
    and also have a composite primary key for the table as follows :
    add constraint PK_FLTRPTDATA primary key (ESN, PERIODID, YEARID, REPORTID, ENTRYID, OPERATORID, ACID)
    using index
    So I expect that I can only insert a new row into the table if the combination of values for ESN,PERIODID,YEARID,REPORTID,ENTRYID,OPERATORID and ACID are unique.
    I am running some software that inserts new rows into the table (via an INSERT SQL statement).
    When the software runs, it inserts a certain number of rows, but then stops when inserting one of the rows with a Violation of PRIMARY KEY constraint 'PK_FLTRPTDATA'. Cannot insert duplicate key in object 'fltRPTDATA' error.
    This implies that the row being inserted contains values for the composite key columns that are NOT unique. However, when I look at the data it fails to insert, I can see that there are NO rows in the table for this combination of column values.
    If I then try to MANUALLY insert the same row myself (via my own SQL statement in SQL Developer), the row is inserted with no error.
    When I run the software, the first thing it does is delete any rows in the table that it will subsequently insert, so there cannot be any duplicate entries in the table before the inserts take place. I have run the SQL statement that does the deletion myself manually, and it does delete all of the relevant rows.
    I have checked the code (I am not the author), and I cannot see anything that would cause the same INSERT to be executed twice.
    I have checked the log file generated by the software, and the INSERT is only attempted once (according to the log).
    I don't understand why the insert fails when I run the software, and I am wondering if anyone can shed any light on the issue? Has anyone seen this scenario before where you get a PRIMARY KEY constraint violation on a composite key, where the data being inserted IS unique?
    Thanks for any help and apologies if this is in the wrong forum,
    Jason.

    >
    I don't understand why the insert fails when I run the software, and I am wondering if anyone can shed any light on the issue? Has anyone seen this scenario before where you get a PRIMARY KEY constraint violation on a composite key, where the data being inserted IS unique?
    >
    One way to find those records would be to create and use a dml error log table. Then those records would get logged to the log table and would not prevent the insert of the valid records.
    See Loading Tables in the DBA Guide
    http://docs.oracle.com/cd/E11882_01/server.112/e17120/tables004.htm#InsertDMLErrorLogging
    Then you can examine the records in the log table and see why they were rejected.

  • Getting Around Key Constraint

    Table A is a parent of Table B, where Table B really only serves as an intermediary table associating Table A's records with some Table C (also a parent of table B).
    As such, Table B is FK'd as a child of both Tables A & C. In order to delete records from Table A, a subquery against table B must be performed (relating table A and table C's fields).
    So my task is to purge certain records from this schema based on the composite key in table C.
    This is the order I have to go in because of the key constraints:
    Delete From table B
    Delete From table A
    Delete From table C
    However, in order to delete from table A, its children rows in record B must be accessed because the entire deletion stems off a subquery select with a composite key from table C (which must then be translated through table B to get to the correct records in table A)
    Naturally, the DBAs didn't enable cascade delete anywhere in this entire schema (sigh). I have no ability to change anything about the database, and because of a number of concerns, I can't write to a temp table and I can't pull anything at all into the executing program's memory.
    Is there anyway to do this. (Sorry if Table A/B/C is confusing. I can give them real names later)

    Hi,
    Have a look at this sample:
    This code
    drop table transaction cascade constraints;
    drop table Invoice cascade constraints;
    drop table Invoice_Transaction cascade constraints;
    create table Transaction
      ID_ NUMBER,
      LBL_T VARCHAR2(50 CHAR)
    create table Invoice
      ID_ NUMBER,
      LVL_I VARCHAR2(50)
    create table Invoice_Transaction
      ID_TRANSACTION NUMBER,
      ID_INVOICE NUMBER
    alter table transaction add constraint t_pk primary key(id_);
    alter table invoice add constraint i_pk primary key(id_);
    alter table Invoice_Transaction add constraint it_pk primary key(id_transaction,id_invoice);
    alter table Invoice_Transaction add constraint it_t foreign key (id_transaction) references transaction(id_);
    alter table Invoice_Transaction add constraint it_i foreign key (id_invoice) references invoice(id_);
    insert into transaction values (1,'NA1');
    insert into transaction values (2,'NA2');
    insert into invoice values (1,'I1');
    insert into invoice values (2,'I2');
    insert into invoice values (3,'I3');
    insert into invoice values (4,'I4');
    insert into invoice_transaction values (1,1);
    insert into invoice_transaction values (1,2);
    insert into invoice_transaction values (1,3);
    insert into invoice_transaction values (2,4);
    commit;
    select lbl_t, lvl_i
    from transaction t, invoice i, invoice_transaction it
    where t.id_ = it.id_transaction
    and i.id_ = it.id_invoice;
    create or replace procedure remove_transaction(pIdTrans IN NUMBER)
    IS
      CURSOR cInvTrans IS
          SELECT id_invoice
          FROM Invoice_Transaction
          WHERE id_transaction = pIdTrans
          FOR UPDATE;
    BEGIN
      FOR vInvTrans IN cInvTrans
      LOOP
        DELETE FROM Invoice_Transaction WHERE CURRENT OF cInvTrans;
        DELETE FROM invoice WHERE id_ = vInvTrans.id_invoice;
      END LOOP;
      DELETE FROM TRANSACTION WHERE ID_ = pIdTrans;
      COMMIT;
    END;
    CALL remove_transaction(1);
    select lbl_t, lvl_i
    from transaction t, invoice i, invoice_transaction it
    where t.id_ = it.id_transaction
    and i.id_ = it.id_invoice;
    Generates this output
    drop table transaction succeeded.
    drop table Invoice succeeded.
    drop table Invoice_Transaction succeeded.
    create table succeeded.
    create table succeeded.
    create table succeeded.
    alter table transaction succeeded.
    alter table invoice succeeded.
    alter table Invoice_Transaction succeeded.
    alter table Invoice_Transaction succeeded.
    alter table Invoice_Transaction succeeded.
    1 rows inserted
    1 rows inserted
    1 rows inserted
    1 rows inserted
    1 rows inserted
    1 rows inserted
    1 rows inserted
    1 rows inserted
    1 rows inserted
    1 rows inserted
    commit succeeded.
    LBL_T                                              LVL_I                                             
    NA1                                                I1                                                
    NA1                                                I2                                                
    NA1                                                I3                                                
    NA2                                                I4                                                
    4 rows selected
    procedure remove_transaction(pIdTrans Compiled.
    CALL remove_transaction(1) succeeded.
    LBL_T                                              LVL_I                                             
    NA2                                                I4                                                
    1 rows selectedHTH!
    Yoann.

Maybe you are looking for

  • Flash Builder 4.7 with Eclipse Kepler

    Hi, I'm trying to install the Adobe Flash Player 4.7 with Eclipse Kepler. I'm using the Adobe Flash Builder 4.7 Plugin-in Utility. It seems that this version of the Builder is not compatible with the Eclipse Kepler but only with Eclipse Indigo or Ecl

  • No Icon for newly opened software in the DOCK

    i am reconfiguring my dock (starting fresh and long story) and i am opening software (for instance Messages) for the first time so that i can run a KEEP IN DOCK as i reorganize this data and for some reason i am not seeing an ICON for this software i

  • Site to Site VPN working without Crypto Map (ASA 8.2(1))

    Hi All, Found a strange situation on our ASA5540 firewall : We have couple Site to Site VPNs and also enable cleint VPN on the ASA, all are working fine. But found a Site to Site VPN is up and running without crypto map configuration. Is it possible

  • Programmatic User Authentication in JHS 10.1.2

    Hi, I've been trying to use JHS 10.1.2. and the Programmatic User Authentication example of 9.0.5.2 but this obviously does not seem to work. Could you please supply information how to enable programmatic User Authentication in JSH 10.1.2? Thanks Wil

  • Com.sap.portal.htmlb in SSL

    Hello, We have implemented SSL on the portal platform (on the J2EE) and it seems to be working for the most part.  We are using it with Kerberos authentication.  We have noted that there are some issues and they mostly revolve around the com.sap.port