Issue with INSERT INTO, throws primary key violation error even if the target table is empty

Hi,
I am running a simple
INSERT INTO Table 1 (column 1, column 2, ....., column n)
SELECT column 1, column 2, ....., column n FROM Table 2
Table 1 and Table 2 have same definition(schema).
Table 1 is empty and Table 2 has all the data. Column 1 is primary key and there is NO identity column.
This statement still throws Primary key violation error. Am clueless about this? 
How can this happen when the target table is totally empty? 
Chintu

Nope thats not true
Either you're not inserting to the right table or in the background some other trigger code is getting fired which is inserting into some table which causes a PK violation. 
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

Similar Messages

  • ODI Selective Reverse throws Primary Key Violation error

    Hi John,
    Hope you are doing good.
    The version of ODI  is 10.1.3.4.5
    I was trying to reverse an MS SQL table using selective reverse and its throwing the below error
    com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint 'PK_COL'. Cannot insert duplicate key in object 'dbo.SNP_COL'.
    Also the error says - Technology or Driver does not support Reverse engineering
    I reversed the same table yesterday and it went fine. But today i wanted to reverse an another table from the same database but its giving an error. I tried deleting the Model itself and tried reversing the both tables and now its not reversing the first on either.
    Please suggest.
    Thanks,
    Sravan

    dear
    you have performed more than once the same reverse engineering.
    If the problem is a doubling in snp * repository, you could delete rows via plsql this process and try again
    tell me if this is not working or if

  • SSIS Upsert Primary Key Violation error

    Hello,
    I created an SSIS package with look up transform. My source is OLE DB Source and destination is OLEDB destination with Lookup no match output and OLEDB command with Lookup match output.
    I am inserting data in destination database if records donot exist or running a stored proc in OLEDB command if the records already exist.
    Still I am receiving a 
    Violation of PRIMARY KEY constraint 'PK_'. Cannot insert duplicate key in object 'dbo.tablename'. The duplicate key value is (734eb1e6-9987-41b6-a143-0039726df29d)."
    Can some one tell me where I am doing it wrong. Shd I change the lookup transform to a different transform?
    Experts I Need your inputs.
    Thanks a ton

    MERGE command inserts, updates or deletes:
    http://agilebi.com/jwelch/2007/07/05/sql-server-2008-using-merge-from-ssis/#86
    http://technet.microsoft.com/en-us/library/bb522522.aspx
    http://technet.microsoft.com/en-us/library/cc280522.aspx
    Kalman Toth Database & OLAP Architect
    SELECT Video Tutorials 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Primary key Violation Error

    Hi all...
    I hace created a Master table and a detail table. the detail table can have multiple records corresponding to a code in master table.this is the case which i want but its giving error of violation of primary key in detail table due to bydefault field Code in the table
    Thanks in advance

    Hi
    Good way are creating of UDO using these tables:
    - Master = MASTER_DATA;
    - Details = MASTER_DATA_ROWS.
    If you import data you need to give values to saome SAP attributes.
    Look this link [Thread: How to import data from excel to UserDefined Fields|How to import data from excel to UserDefined Fields;. May be it can help you.
    Regards
    Sierdna S.

  • How can I insert an aggregated column name as a string in the target table?

    I have a large source table, with almost 70 million records.  I need to pull the sum of four of the columns into another target table, but instead of having the same four target columns I just want to have two.
    So, let's take SUM(col1), SUM(col2), SUM(col3), and SUM(col4) from the source DB & insert them into the target like this:
    SOURCE_COLUMN
    | AMOUNT
    1 col1
    | SUM_AMOUNT
    2 col2
    | SUM_AMOUNT
    3 col3
    | SUM_AMOUNT
    4 col4
    | SUM_AMOUNT
    I know how to do this in four separate Data Flows using the source, an Aggregation Transformation, a Derived Column (to hard code the SOURCE_COLUMN label), and destination... but with this many records, it takes over 3 hours to run because it has to loop
    through these records four separate times instead of once.  Isn't there a way to do this with one Data Flow?  I'm thinking maybe Conditional Split?
    Any help is appreciated, thanks!

    Hi ,
      This could be achieved using UNPIVOT transformation. The below sample uses the below source query
    SELECT 1 AS COL1,2 AS COL2,3 AS COL3,4 AS COL4
    setup the UNPIVOT transformation as below
    The output of unpivot transformation will be as below
    Hope this helps.
    Best Regards Sorna

  • Primary key violation exception in auto increment column

    Hi All,
    I am facing one issue in Multi threaded environment.
    I am getting Primary key violation exception in auto increment column. I have a table and the primary key is the auto increment column, and I have a trigger which is populating this column.
    5 threads are running and inserting the data in the table and throwing Primary key violation exception randomly.
    create table example (
    id number not null,
    name varchar2(30)
    alter table example
    add constraint PK1example primary key (id);
    create sequence example_id_seq start with 1 increment by 1;
    create or replace trigger example_insert
    before insert on example
    for each row
    begin
    select example_id_seq.nextval into :new.id from dual;
    end;
    Any idea how to handle auto increment column(trigger) in Multi threaded environment??
    Thanks,

    user13566109 wrote:
    Thanks All,
    Problem was in approach; removed the trigger and placed a seq.nextval in insert query. It has resolved the issue.I very much suspect that that was not the issue.
    The trigger would execute for each insertion and the nextval would have been unique for each insertion (that's how sequences work in oracle), so that wouldn't have been causing duplicates.
    I suspect, more likely, that you had some other code somewhere that was using another sequence or some other method of generating the keys that was also inserting into the same table, so there was a conflict in the sources of the sequences being generated.
    The way you showed you had coded above, was a perfectly normal way to assign primary keys from a sequence, and is not a problem in a multi user/threaded environment.

  • Having a problem with creating/using a primary key on a view

    I have a problem with a primary key on a view
    I created the view and primary key as follows:
    CREATE OR REPLACE FORCE VIEW "MDD"."ROCK_LU" ("DESCRIPTION",
         UNIQUE ("DESCRIPTION") RELY DISABLE,
         CONSTRAINT "ROCK_LU_PK" PRIMARY KEY ("DESCRIPTION") RELY DISABLE) AS
    SELECT DESCRIPTION
    FROM MRMC_LU
    WHERE ROCK = 'T';
    The view with the primary key appears to have been created as there were no error messages. (The above was from the sql tab in sql developer.)
    When I try to create the foreign key on my mdd_hr table - I get an error
    /* hr_name - foreign key */
    ALTER TABLE mdd_hr add CONSTRAINT hr_name_fk FOREIGN KEY (hr_name) REFERENCES rock_lu(description);
    Error report:
    SQL Error: ORA-02270: no matching unique or primary key for this column-list.
    When I lookup the index in sql developer, rock_lu_pk is not there.
    All my other foreign keys work - but I don't understand what I am doing wrong with this one. Please help.
    glenn
    Background - as to why I want to use a view as a lookup table.
    The MRMC_LU table that the view is created from is structured like:
    DESCRIPTION - MINERAL - ROCK - MODIFIER - COMMODITY
    ANHYDRITE - T - T - T
    APLITE - T - - T
    GRAPHITE - T - - - T
    GREYWACKE - - T
    DESCRIPTION is a list of all names of minerals, rocks, modifiers and commodities. T is entered in each valid field. Often a description name is used for both a mineral and a rock or a mineral and a commodity or any other combination. Because this database is just starting up, it was more efficient to create one table that could be updated (and thereby automatically update the MINERAL_LU, ROCK_LU, MODIFIER_LY, COMMODITY_LU views) rather than create and maintain four separate but similar tables. A primary key cannot be generated for the MRMC_LU table as there are nulls in each column
    except DESCRIPTION.
    Perhaps there is a smarter way to do this?

    http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_85a.htm#2065512
    You can specify constraints on views and object views. You define the constraint at the view level using the out_of_line_constraint clause. You define the constraint as part of column or attribute specification using the inline_constraint clause after the appropriate alias.
    Oracle does not enforce view constraints. However, operations on views are subject to the integrity constraints defined on the underlying base tables. This means that you can enforce constraints on views through constraints on base tables.
    Restrictions on View Constraints
    View constraints are a subset of table constraints and are subject to the following restrictions:
    You can specify only unique, primary key, and foreign key constraints on views. However, you can define the view using the WITH CHECK OPTION clause, which is equivalent to specifying a check constraint for the view.
    Because view constraints are not enforced directly, you cannot specify INITIALLY DEFERRED or DEFERRABLE.
    View constraints are supported only in DISABLE NOVALIDATE mode. You must specify the keywords DISABLE NOVALIDATE when you declare the view constraint, and you cannot specify any other mode.
    You cannot specify the using_index_clause, the exceptions_clause clause, or the ON DELETE clause of the references_clause.
    You cannot define view constraints on attributes of an object column.
    Rgds.

  • Primary key violation when inserting records with insert_identity and ident_current+x

    My problem is this: I have data in a couple of temporary tables including
    relations (one table referencing records from another table by using
    temporary keys).
    Next, I would like to insert the data from the temp tables to my productive tables which have the same structure but their own identity keys. Hence, I need to translate the 'temporary' keys to regular identity keys in my productive tables.
    This is even more difficult because the system is highly concurrent, i.e. multiple sessions may try to insert
    data that way simultaneously.
    So far we were running the following solution, using a combination of
    identity_insert and ident_current:
    create table doc(id int identity primary key, number varchar(100))
    create table pos (id int identity primary key, docid int references doc(id), qty int)
    create table #doc(idx int, number varchar(100))
    create table #pos (docidx int, qty int)
    insert #doc select 1, 'D1'
    insert #doc select 2, 'D2'
    insert #pos select 1, 10
    insert #pos select 1, 12
    insert #pos select 2, 32
    insert #pos select 2, 9
    declare @docids table(ID int)
    set identity_insert doc on
    insert doc (id,number)
    output inserted.ID into @docids
    select ident_current('doc')+idx,number from #doc
    set identity_insert doc off
    -- Since scope_identity() is not reliable, we get the inserted identity values this way:
    declare @docID int = (select min(ID) from @docids)
    insert pos (docid,qty) select @docID+docidx-1, qty from #pos
    Since the request to ident_current() is located directly in the insert statement, we always have an implicit transaction which should be thread safe to a certain extend.
    We never had a problem with this solution for years until recently when we were running in occasional primary key violations. After some reasearch it turned out, that there were concurrent sessions trying to insert records in this way.
    Does anybody have an explanation for the primary key violations or an alternative solution for the problem?
    Thank you
    David

    >> My problem is this: I have data in a couple of temporary tables including relations (one table referencing records [sic] from another table by using temporary keys [sic]). <<
    NO, your problem is that you have no idea how RDBMS and SQL work. 
    1. Rows are not anything like records; this is a basic concept.
    2. Temp tables are how old magnetic tape file mimic scratch tapes. SQL programmers use CTEs, views, derived tables, etc. 
    3. Keys are a subset of attributes of an entity, fundamental characteristics of them! A key cannot be temporary by definition. 
    >> Next, I would like to insert the data from the temp tables to my production tables which have the same structure but their own IDENTITY keys. Hence, I need to translate the 'temporary' keys to regular IDENTITY keys in my productive tables. <<
    NO, you just get worse. IDENTITY is a 1970's Sybase/UNIX dialect, based on the sequential file structure used on 16-bit mini computers back then. It counts the physical insertion attempts (not even successes!) and has nothing to with a logical data model. This
    is a mag tape drive model of 1960's EDP, and not RDBMS.
    >> This is even more difficult because the system is highly concurrent, i.e. multiple sessions may try to insert data that way simultaneously. <<
    Gee, that is how magnetic tapes work, with queues. This is one of many reasons competent SQL programers do not use IDENTITY. 
    >> So far we were running the following solution, using a combination of IDENTITY_INSERT and IDENT_CURRENT: <<
    This is a kludge, not a solution. 
    There is no such thing as a generic “id” in RDBMS; it has to be “<something in particular>_id” to be valid. You have no idea what the ISO-11179 rules are. Even worse, your generic “id” changes names from table to table! By magic, it starts as a “Doc”,
    then becomes a “Pos” in the next table! Does it wind up as a “doc-id”? Can it become a automobile? A squid? Lady Gaga? 
    This is the first principle of any data model; it is based on the Law of Identity; remember that from Freshman Logic 101? A data element has one and only one name in a model. 
    And finally, you do not know the correct syntax for INSERT INTO, so you use the 1970's Sybase/UNIX dialect! The ANSI/ISO Standard uses a table consrtuctor: 
    INSERT INTO Doc VALUES (1, 'D1'), (2, 'D2'); 
    >> We never had a problem with this solution for years until recently when we were running in occasional PRIMARY KEY violations. After some research it turned out, that there were concurrent sessions trying to insert records [sic] in this way. <<
    “No matter how far you have gone down the wrong road, turn around.” -- Turkish proverb. 
    You have been mimicking a mag tape file system and have not written correct SQL. It has caught up with you in a way you can see. Throw out this garbage and do it right. 
    --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

  • Need to create a new row in table with same data as Primary key, but new PK

    Hello Gurus ,
    I have a table with one column as primary key, I need to create a new row in the table, but with same data as in one of the rows, but with different primary key, in short a duplicate row with diferent primary key ..
    Any ideas of how it can be done without much complication?
    Thanks in advance for your reply.
    Reards,
    Swapneel Kale

    user9970447 wrote:
    Hello Gurus ,
    I have a table with one column as primary key, I need to create a new row in the table, but with same data as in one of the rows, but with different primary key, in short a duplicate row with diferent primary key ..
    Any ideas of how it can be done without much complication?
    Thanks in advance for your reply.
    Reards,
    Swapneel Kalesomething like
    insert into mytable values ('literal for new pk',
                                           select non-pk-1,
                                                    non-pk-2,
                                                    non-pk-n
                                           from mytable
                                           where pk-col = 'literal for existing pk')

  • Issue with Insert in SP

    Gurus,
    I have an issue with inserting rows into temp table through SP.
    Here is my proc. its running fine. After the execution completed when i try to select the rows from srini_temp table its showing 0 rows. Whats wrong here.
    CREATE PROCEDURE BO_HR_RPT.SRINI_TEST AS
    BEGIN
    insert into BO_HR_RPT.srini_temp (
    COURSE_TITLE,
    COURSE_ID,
    CLASS_NO,
    DELIVERY_METHOD,
    LEARNER_OWN,
    DURATION,
    score,
    VENDOR,
    START_DATE,
    END_DATE,
    INSTRUCTOR_NAME,
    TRANS_STATUS,
    LEARNER_NAME,
    LEARNER_EMP_TYPE,
    INSTRUCTOR_OWN,
    INSTRUCTOR_EMP_TYPE,
    EFFT_PERIOD,
    YEAR,
    AS_OF_DATE,
    LMS_SOURCE,
    REPORT_CATEGORY)
    SELECT COURSE_TITLE,
    COURSE_ID,
    CLASS_NO,
    CASE WHEN COURSE_ID LIKE 'TIS%' OR COURSE_ID LIKE 'TIWEB%' OR COURSE_ID LIKE 'TIVLAB%' OR COURSE_ID LIKE 'TIWVT%'
    OR COURSE_ID LIKE 'STARELT%' OR COURSE_ID LIKE 'TIELT%' OR DELIVERY_METHOD ='Web Based Training'
    OR DELIVERY_METHOD = 'e-Learning or via backend Import' THEN 'E-Learning'
    WHEN DELIVERY_METHOD = 'IDL' THEN 'IDL'
    WHEN DELIVERY_METHOD = 'IDL Replay' THEN 'Replay'
    ELSE INITCAP(DELIVERY_METHOD) END AS DELIVERY_METHOD,
    RTRIM(LEARNER_OWN) as LEARNER_OWN,
    CASE WHEN LMS_SOURCE ='SABA' THEN ROUND(DURATION/60,1)
    ELSE DURATION END AS DURATION,
    CASE WHEN SCORE='0' then '' else score END as score,
    CASE WHEN (vendor_name IS NOT NULL) AND (UPPER(SUBSTR(COURSE_ID,1,2)) = 'TV') then vendor_name
    WHEN COURSE_ID LIKE 'TIWEB%' then 'SKILLSOFT'
    WHEN COURSE_ID LIKE 'TIVLAB%' then 'ELEMENTK'
    ELSE 'N' END AS VENDOR,
    START_DATE,
    END_DATE,
    INITCAP(INSTRUCTOR_NAME) AS INSTRUCTOR_NAME,
    TRANS_STATUS,
    INITCAP(LEARNER_NAME) AS LEARNER_NAME,
    INITCAP(LEARNER_EMP_TYPE) AS LEARNER_EMP_TYPE,
    RTRIM(INSTRUCTOR_OWN),
    INITCAP(INSTRUCTOR_EMP_TYPE) AS INSTRUCTOR_EMP_TYPE,
    trim(initcap(TO_CHAR(TRUNC(NVL(END_DATE,START_DATE)),'MONTH'))) AS EFFT_PERIOD,
    TO_CHAR(TRUNC(NVL(END_DATE,START_DATE)),'YYYY') AS YEAR,
    TRUNC(ADD_MONTHS(LAST_DAY(load_date) ,-1)) AS AS_OF_DATE,
    LMS_SOURCE,
    REPORT_CATEGORY
    FROM BO_HR_RPT.ELM_GLD_MASTER_BASE
    where ROWNUM <= 10
    ORDER BY COURSE_ID,CLASS_NO,START_DATE,END_DATE,INSTRUCTOR_NAME;
    COMMIT;
    END;
    Thanks for great help.
    Srini

    Are you completely sure this isn't a global temporary table?
    it really would explain your problems!
    Have you got access to run a
    select tablename from all_tables where TEMPORARY = 'Y'[pre]                                                                                                                                                                                                                                                                                                                                                                                                           

  • CP 6 issue with inserted videos

    Hi All,
    I have an issue with inserted videos in CP6. They play in preview (F8) but not in published output (swf nor html).
    This is what I do:
    The videos created with CP6, Record new Demo
    output cpvc
    open cpvc in CP 6
    publish see settings below:
    Now I want to insert the captured and published demo into my training CP6 project
    click 'Video' on menu bar -> Insert Video -> select 'Event Video' -> browse to the file on my computer -> select file (mp4) - click OK
    Video gets loaded into CP6 project with default skin
    Before save the changes of the project I change the settings on the property panel to:
    Now I preview my project
    Press F8
    Preview is generated
    video demo plays automatically as expected
    This all even works well with multiple demo videos on one slide which can be selected by clicking different show me buttons (advanced actions created to show and hide according videos)
    BUT now I publish my project and nothing works anymore, videos do not show on scene and cannot be selected with respective show me buttons
         Publishing settings are:
    At the end of the publishing dialogue I click to view output in web browser (IE9) and there starts the trouble:
    IE shows up withfollowing dialogue:
    I allow blocked content and select cancel in the following dialogue box:
    And the training loads, everything works fine except the videos integrated to start automatically there is a blank space nothing.
    Does anyone have an idea solution for me?
    I am so puzzled and do not know hoe to proceed...
    Thanks in advance for your reply!!!
    Stephanie

    Hi RodWard,
    Thanks for your fast reply!!!
    The video files are present in the same folder as the SWF publish location.
    The drive letter is on my local PC with multiple partitions and not a network drive.
    Flash global security settings are set for E:
    To your last suggestion about file naming I did the following:
    Generate new mp4s
    Name them only with alphanumerics ie. DemoScroll
    insert them into project
    preview OK
    publish and check if demos are in folder - yes they are
    open html in IE9  - NOK!!!
    Now frustration rose...
    So I tried one thing that I had not yet tried - open html in FireFox and there it is OK :-)
    I do not understand....BUT we need to be able to support IE!!!!
    Do you think there are specific settings that need to be changed in IE to make it work?
    I would highly appreciate a suggestion what to look for in IE...
    Do you think it is related to IE9?  ´
    Since I have IE 9 and CP6 I also get the LMS messages and actriveX message when viewing projects in browser.
    Looking forward to your help.
    Thanks in advance Stephanie

  • Overwriting a record with part of same primary key

    Hello Everyone,
    Could anyone please give a suggestion about how to overwrite the record with part of same primary key?
    I have  5 key fields.
    A1
    A2
    A3
    A4
    A5
    I have to overwrite the record if A5 changes with same A1 A2 A3 A4.
    I cannot take off A5 as part of primary key. If I use modify or insert, its creating a new record with the new A5. But I am still having the old record in the table (with old A5), which I don't want it to be there.
    Thank you,
    Rushi

    hi,
    That's right.
    u have to delete record from database table .....
    then u can add a new record...
    use delete <database_table> from table <internal_table>

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

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

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

  • My iPhone4 is showing no service so i power down but when i power back up it says to plug into itunes and restore, i had this same issue with another iPhone and apple replaced it but its doing the same thing on this phone any help would be apprecaited

    my iPhone4 is showing no service so i power down but when i power back up it says to plug into itunes and restore, i had this same issue with another iPhone and apple replaced it but its doing the same thing on this phone any help would be apprecaited

    AAAAAANNNNNNDDDDDDD go figure no one can help!!!!! i just dont know what to do, i guess no-one else does either lol!!!! thanks anyway!!!!!

  • Lion Ichat client issues with logging into SL Ichat server

    We run the iChat server on our OD master running 10.6.8. We have about 250 users and it's working great for everyone on Leopard or SL (the majority of our users).
    We just started upgrading people to Lion, as well as getting some new lion machines.  The people who are on Lion Pre-Configured machines seem ok, but the people who we upgrade are having issues with logging into it.  Sometimes it will work just fine, and other times they just can't log in.  They get the ~ symbol by their status and can't connect to the server. 
    The only fix seems to be trashing their prefs AND rebooting, just trashing them or just rebooting don't seem to be enough to fix this. Anyone seen or have a better fix for this? It has happened more than once for the same user.

    Same problem here [https://discussions.apple.com/message/23114338#23114338].
    Were you ever able to troubleshoot or fix this? File a bug report?

Maybe you are looking for

  • PDF in iBooks, search question

    Hi there, I have a client who uses iBooks to view 2 pdfs on her iPad. The pdfs were created in InDesign, 2 different designers (not me). The issue she encountered is with search results in iBooks. In the first book, when I search for a particular num

  • How to create dropdown ?

    Hi, i have created some new fields in BUPA using EEWB by Create extension wizard... i have assigned it to design layer object . i need this field to be a dropdown list ...... A have added allowed values to corresponding view of this field....... BUt

  • Applet freezes requesting which cert should use for a SSL connection

    Hello everyone, I have a strange problem. Applet freezes when it request which certificate should it use to connect to the server through a SSL connection. It works fine if it does not show the "choose certificate" window. I can not give more clues,

  • Chirps when charging is this normal

    Last night while charging my Ipad it would make a little chirping like beep periodically. I eventually turned down the volume so as not to hear it. What is the deal.

  • Link between sales contract and down payment

    Hi all, Is there a way to link sales contract with down payment if down payment is created before sales contract? Please respond. Best Regards, AI.