[dba-SQLServer] deleting duplicates across multiple tables

Arthur Fuller fuller.artful at gmail.com
Fri Jun 6 15:49:25 CDT 2008


Cascade delete would automatically take care of it. You could also code a
delete trigger. It would grab the value of the PK from the inserted table
then delete matching values in the related tables. Not much coding required.
This would "automate" future deletes, but obviously can't do anything about
rows already deleted. However, you could find the orphaned child rows using
an outer join from the child table and criteria of "Parent.PK IS NULL".

hth,
Arthur

On Fri, Jun 6, 2008 at 2:21 PM, Susan Harkins <ssharkins at gmail.com> wrote:

> http://blogs.techrepublic.com.com/datacenter/?p=372
>
> The above article discusses a simple technique for deleting duplicates in a
> single table. A reader wants to know how to expand it to deal with related
> tables.
>
> You can use referential integrity to prevent orphans, but... if the
> duplicates have related duplicates, you still end up with duplicates -- any
> idea how to expand this?
>
> Susan H.
>
> _______________________________________________
> dba-SQLServer mailing list
> dba-SQLServer at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
> http://www.databaseadvisors.com
>
>



More information about the dba-SQLServer mailing list