2

We're moving some processes from a Sql Server database environment which allows identity columns to a Sql Server database environment that does not allow identity columns. How can we effeciently create unique integer values for surrogate primary keys without using the identity construct?

As for why we can't use an identity column, Microsoft's Parallel Data Warehouse splits tables between physically distinct servers. Microsoft removed the identity feature from the PDW because you would have to communicate between all of the servers to find the new identity value for each insert in a distributed table, which pretty much negates the point of parallelism.

quillbreaker
  • 6,119
  • 3
  • 29
  • 47

3 Answers3

1

Without knowing why you can't use an identity, or how you use them (e.g. primary key, count of records, sequence of events), I'm not sure anyone can recommend a particular replacement.

That said, I think you are looking to create a sequence.

SQL Server 2012 adds sequences.

Older versions of SQL Server require different methods to implement this, though they all have downfalls compared to native identities or sequences.

Community
  • 1
  • 1
Tim Lehner
  • 14,813
  • 4
  • 59
  • 76
0

I'd be interested to find out why your new environment does not allow identity columns (not saying there's not a good reason, but I've never encountered that before).

With that said, the best solution I can think of is to use a trigger on inserts that finds the max value of the pseudo-identity column and adds 1.

Jeff B
  • 155
  • 7
0

Here's one technique I've used. It's not without its warts, but it does get the job done without any annoying race conditions. It's my answer to sql server: generate primary key based on counter and another column value

Community
  • 1
  • 1
Nicholas Carey
  • 71,308
  • 16
  • 93
  • 135