[thelist] Merge Duplicate Records in MySQL/PHP

Nan Harbison nan at nanharbison.com
Sun Jul 6 14:06:51 CDT 2008


This makes total sense, but I would never have thought of this. So what do
you use for the alternative key? I can't think of one field in my database
which would always be unique.

Thanks Rudy!

Nan

-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of r937
Sent: Sunday, July 06, 2008 8:55 AM
To: thelist at lists.evolt.org
Subject: [thelist] Merge Duplicate Records in MySQL/PHP

> What is wrong with using an autoincremented ID?

it lulls you into a false sense of security

many people create one, thinking that this is all they need to do ("because
every table needs a primary key")

they forget to declare UNIQUE constraints for the "real" primary key (i call
it the "real" PK but the correct name is alternate key or candidate key)

thus, one of the more frequently asked questions on database forums is "omg
halp plz, how do i delete all but one of my duplicate rows??!!1!"

naturally, if you can identify a UNIQUE constraint, then this would serve
well as the PK

at that time, having an auto_increment as a surrogate PK is okay, especially
if there are going to be foreign keys referencing it (this is sometimes
problematic when the real PK contains large or multiple columns)

helps?

;o)


-- 

* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester and archives
of thelist go to: http://lists.evolt.org Workers of the Web, evolt ! 




More information about the thelist mailing list