views:

36

answers:

3

Hi,

I tend to rename a profile user uploaded picture to the corresponding id of that column in the profile table, but recently i saw several projects adding an extra column in the table to identify the related photo (uniqueid, md5 or guid), what is the benefit of doing that, i see it redundant as i can already identify the photo with the profile primary id column (assuming that a profile has only one photo.)

Thanks. Yehia A.Salam

+1  A: 

The reason to use a GUID in such cases is that they can't be guessed.

When you use the ID field from a user (typically an auto incrementing int), you can try random numbers to get results. With a GUID this is 'impossible'.

At least, that is why I use GUID's in such cases. The reason might be different in your situation.

Dennis Haarbrink
+1  A: 

Once you've defined a non significant key you can refactor or redesign your database without having to worry about changing the ID.

As non significant keys guid have multiple advantages, they are unique in time and space and do not require a roundtrip on database to be calculated.

Regards

Massimo

massimogentilini
A: 

if the GUID is based on the MD5 (or SHA1) hash of the content this could help in deduplicating identical pictures with different names.

The other reason is when merging images from more than one user: There will not be a collision in the GUID column if the GUID is a random / MAC+Time based one

Dominik Weber