1

I apologize in advance if this is a duplicate, I'm not sure exactly what I should be searching for.

Recently I watched this nifty video on Channel 9 about database federation in SQL Azure. At first I was surprised by the fact that identity columns are not supported by SQL Azure Federation, but it makes sense. If you have a table that is split between 2 (or more) databases, and they have no way to share their identity increment value, you could end up with 2 (or more) entities sharing the same primary key.

The video touched lightly on how to deal with this problem, mentioning using something like a Guid for a PK instead of an integer-based identity column. I know that at least MSSQL will create a clustered index on the PK by default, and it is bad to have a clustered index on a Guid (or uniqueidentifier) type. I'm by no means a relational expert, but I also believe that Guid's have a performance degradation when compared to integer-based types for PK-based lookups.

So this got me wondering, what might an integer-based PK pattern look like for a horizontally federated database look like? Back when I wrote old school EJB's and we needed to generate an integer for a primary key, we had to have a separate sequence lookup table to replace the rdbms identity/auto-increment features. I recall this was was painful, as many other things with EJB's were back then.

What are the commonly-accepted patterns, if any, for assigning primary keys in a horizontally federated database table? Given my current knowledge I would lean away from Guid's because of performance degradation, and I would lean away from sequential lookup indices because of development cost and added complexity (mostly development cost). What should I be leaning toward?

danludwig
  • 46,965
  • 25
  • 159
  • 237

1 Answers1

1

Something like this might be useful, depending on the nature of your app

http://blog.tatham.oddie.com.au/2011/07/14/released-snowmaker-a-unique-id-generator-for-azure-or-any-other-cloud-hosting-environment/

Craig
  • 36,306
  • 34
  • 114
  • 197
  • Thanks for the link. Funny, I was just reading your question about MVC4 async, reading the tutorial and looking for an answer... – danludwig Jul 05 '12 at 05:18
  • Yes, I like snowmaker -- especially the interface for new providers. Thanks again! – danludwig Jul 07 '12 at 16:41