Re: Violation of primary key

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Dan Guzman (guzmanda_at_nospam-online.sbcglobal.net)
Date: 10/30/04


Date: Sat, 30 Oct 2004 17:41:42 -0500

Like Kalen said, you won't find any existing dups because this is what a
primary key prevents. You can prove this with a query like:

    SELECT MyPK
    FROM MyTable
    GROUP BY MyPK
    HAVING COUNT(*) > 1

The error is due to the *new* data you are attempting to insert. Check the
primary key values of the data you are trying to insert and either skip the
rows that already exist or delete those from the table before inserting.

-- 
Hope this helps.
Dan Guzman
SQL Server MVP
"kitty" <kitty@discussions.microsoft.com> wrote in message 
news:7649F34D-6B76-4117-AFAC-482A01D1620C@microsoft.com...
> Well, it seems that what I ended up doing was entering records manually
> directly into the database. I was testing a new field that I created and I
> guess I got carried away.  Those new records that I was playing with, I 
> seem
> to have deleted but I cannot find the one that is trunkating my database. 
> Do
> you know of a way to find a hanging record with a duplicate primary key? 
> I
> tried sorting by primary key but I dont' see any doops.  I ran an access
> query where I called it to count doops from my primary key but again, no
> doops.  Do you know a way in wich we can arrange the records enterd last?
>
> Thanks
>
> "Dan Guzman" wrote:
>
>> I can't think of an accidental server or database setting change that 
>> would
>> cause this error to suddenly appear.
>>
>> Did you make any design changes to your 'keycode' table (primary key)? 
>> If
>> not, this is probably a legitimate error due to attempting an insert of
>> duplicate data (same primary key) into the table.
>>
>> -- 
>> Hope this helps.
>>
>> Dan Guzman
>> SQL Server MVP
>>
>> "kitty" <kitty@discussions.microsoft.com> wrote in message
>> news:861F5472-F042-484F-99F2-553A880CD019@microsoft.com...
>> > [Microsoft]]ddbc sql server driver][sql driver] violation of primary 
>> > key
>> > constraint 'aaaaakeycode.pk'.  cannot insert duplicate key in object
>> > 'keycode'(#2627)[Microsoft]]ddbc sql server driver][sql driver] The
>> > statement
>> > terminated.(#3621)
>> >
>> > Please help me, I am a newby and I was looking at the settings in my 
>> > sql
>> > database and when i exited out I must have changed something  because I 
>> > am
>> > getting the eror above.  I checked the settings but nothing seems
>> > different.
>> > Please help me.  Where should I look first?  Second?
>> >
>> > Thanks
>> >
>> > Celia
>>
>>
>> 


Relevant Pages

  • Re: Very slow query
    ... indexed for all the secondary tables, only the primary key is indexed). ... create a new blank database and immediately turn OFF the Name ... With 14 secondary tables or less, my query runs in 1 sec or less. ... in forms, base the form on the primary data table, and use combobox or ...
    (microsoft.public.access.queries)
  • Re: problem using identity column as primary key
    ... >> I am thinking of creating an identity column to use it as primary key ... More and more programmers who have absolutely no database training are ... the gap in the sequence is not filled in and the sequence ... vin CHARNOT NULL REFERENCES Motorpool); ...
    (microsoft.public.sqlserver.programming)
  • Re: Query to merge
    ... Thanks for that insite - I am sure that the additional customers (that would ... simply build your query to give you all records from the one, ... Say it was a customer database. ... customers with the same primary key. ...
    (microsoft.public.access.queries)
  • Re: Is this bad design?
    ... application which is making heavy use of an Access database. ... design but there might be good reasons for doing things this ... Tables with a generated primary key i.e. an id where a number ... Relations can be created on the fly in the query builder and/or ...
    (comp.databases.ms-access)
  • Re: Very slow query
    ... indexed for all the secondary tables, only the primary key is indexed). ... create a new blank database and immediately turn OFF the Name ... With 14 secondary tables or less, my query runs in 1 sec or less. ... in reports, base the report on the type of query described above ...
    (microsoft.public.access.queries)