List:General Discussion« Previous MessageNext Message »
From:Shawn Green (MySQL) Date:September 6 2010 5:39pm
Subject:Re: AW: Dup Key Error Messages
View as plain text  
On 9/6/2010 9:10 AM, Thorsten Heymann wrote:
> No, I think you misunderstood me. I have these keys (in this example)
> 
> 
> -          PRIMARY (id)
> 
> -          UNIQUE (ip_addr)
> 
> -          UNIQUE (print_name)
> 
> And when of of the UNIQUEs is duplicated, I'll wshow user a message WHAT key is a
> doublette.
> 

Actually, that was not what you posted above. In your original example 
you have one primary key and one unique key. That unique key is based on 
the combination of values {`ip_addr`,`print_name`}. This means that all 
of these values pairs are unique

'192.168.1.1','queue1'
'192.168.1.1','queue2'
'192.168.2.1','queue1'
'192.168.2.1','queue2'

If I assume that each row was assigned a sequential ID value, then these 
are rows 1..4 . If I attempted to modify row 1 like this

UPDATE `device` SET `print_name` = 'queue_2' where ID = 1;

Then I would hit a conflict. The combination of

{ip_addr='192.168.1.1',	`print_name='queue2'}

already exists in the row where the ID value is 2.

Even if I parsed the error entire message, it would not tell me which 
element of this UNIQUE key I violated, only that the combination already 
exists and which constraint is protecting that combination.
-- 
Shawn Green
MySQL Principal Technical Support Engineer
Oracle USA, Inc.
Office: Blountville, TN
Thread
Dup Key Error MessagesThorsten Heymann6 Sep
  • Re: Dup Key Error MessagesTompkins Neil6 Sep
    • AW: Dup Key Error MessagesThorsten Heymann6 Sep
      • Re: AW: Dup Key Error MessagesMySQL)6 Sep
  • Re: Dup Key Error MessagesCarsten Pedersen6 Sep
    • AW: Dup Key Error MessagesThorsten Heymann6 Sep
  • Re: Dup Key Error MessagesJoerg Bruehe6 Sep
    • AW: Dup Key Error MessagesThorsten Heymann7 Sep
      • Re: AW: Dup Key Error MessagesChris W7 Sep