Saturday, 29 January 2011

UserId VS UserName

In my Notes database, I want every record to belong to some particular user (it is not Wikipedia, after all).

In the ApplicationServices database, so kindly created for me by the aspnet_regsql tool, there is a table dbo.aspnet_Users, which keeps all the user-related info.


So, when creating my dbo.Note table, I will store, together with all the note-related info, some user identity, to be able to distinguish which note actually belongs to the current user.

The question is: What should I use - UserId or UserName?

Both are unique, UserId by virtue of being a GUID (and also, a primary key), and UserName by virtue of the unique clustered index (technically, it is unique within the application).

So, pro and contra:

Pro:
  • The UserName, being used in every query, will be the perfect candidate for the clustered index, which will guarantee the user-related records are fetched very quickly.
Contra:
  • I am going to have a serious problem once I decide it is possible for two users to have the same user name. Somehow I really doubt it.
  • I might have a problem if I decide I would like to re-use user names, and I don't properly remove the user data left from the previous owner.
So, I go for UserName with the clustered index built on this column.

 

No comments:

Post a Comment