Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Managing duplicate IDs


Message #1 by "Kamal Bennani" <kbennani@e...> on Thu, 1 Nov 2001 17:04:27
Kamal,

I think what you want to end up with is two new tables, USER (USR) and 
GROUP (GRP) with one unique identifier for each. True?

USER (USR)
pk *# usr_id
fk *  grp_id
   *  fname
   ...

GROUP (GRP)
pk *# grp_id
   ...

However, you still have multiple rows of repeating data that you must pull 
together. The usr_id is already unique and can be left as is. I must ask 
you, do you need the ExternalID column? And, what is it used for (who 
references it)?

If not, then, copy your table for recovery sake, drop the ExternalID 
column, delete all the rows with exact duplicates in every column (you'll 
have to do a select distinct * to see what the final set of records should 
look like), and you're done with the USR table. The GRP table should be 
fine as is.

Should you need the ExternalID you will have to ignore the column in your 
select distinct statement to pull out the unique records. Delete the 
duplicate records as metioned above and each user will have one usr_id and 
one ExternalID. I would set a contraint (or sequence) on the ExternalID 
that would verify that it is indeed unique in the future.

Your end solution would then be:

USER (USR)
pk *# usr_id
pk *# etl_id (ExternalID)
fk *  grp_id
   *  fname
   ...


GROUP (GRP)
pk *# grp_id
   ...

Hope this helps you. Good luck.

- RJ

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2
> Hi,
> 
> I have a User table defined by :
> ExternalID int
> UserID int
> FirstName nvarchar (30)
> ...
> 
> and a UserGroup table defined by :
> GroupID int
> UserID int
> ...
> 
> In the User table, UserID is unique while multiple rows may have the 
same 
> ExternalID. In that case, that means that the same user have different 
> UserID.
> 
> My goal is to process the UserGroup and User tables so that for each 
> ExternalID, I have to find all the related UserID, modify the User table 
> to keep only one record for that "user", and modify the UserGroup table 
> accordingly.
> 
> After that operation, I'll have no duplicate ExternalID in the User 
table.
> 
> Any idea on how to do that?
> 
> Best regards
> Kamal

  Return to Index