views:

74

answers:

3

Hi I'm using ms2005 for a simple calendaring system. We have three 'legacy' tables: Groups, Units and Staff.

I need to give each record in the tables a unique identifier (carrying across all 3 tables).

What would be best way to approach this? I am using NHibernate and was was wondering whether that could do it for me.

Anyway, any nods in the right direction much appreciated.

+1  A: 

The usual practice is to create a surrogate primary key on each table using an int with IDENTITY(1,1).

If you need a unique values across systems then use a UNIQUEIDENTIFIER column (GUID).

Mitch Wheat
Maybe; but see my following request for clarification. Use the IDENTITY column; only use UNIQUEIDENTIFIER if you understand what that is, when to use it, and why. Which is unlikely, given your question.
le dorfier
A: 

Are you saying that the same identifier shouldn't appear in more than one table? That would be a fishy assertion that would suggest that more discussion is needed.

It would be a "Bad Smell", in a refactoring sense.

le dorfier
A: 

No not the same identifier. We would like to add an item(Group, unit or Staff) as a resource item to a calendar entry. Then have one join table event_resource as a lookup. With the current set up it is likely that a unit may have the same id as a group etc.

Then I submit that the design is faulty (let others weigh in, though). The resources aren't interchangeable and you don't want to allow them to be viewed as such. I've written such systems and you want to track things by ResourceType/Id rather than just Global ResourceId.
le dorfier
This should not have been an answer but a comment to another answer. Please move it there
Eran Galperin