Multiple TSQL sequences in one sequence

263 Views Asked by At

I need to run sequence number for all of my customers in my SQL Server database.

I have about 1000 customers, I need each and one of them have their own sequence?

How can that be done in TSQL?

Is it possible to make one sequence to serve all purposes?

It doesn't sounds reasonable to created 1000 sequences.

1

There are 1 best solutions below

2
On

Sequence will give you only one number series. To have one per each customer, and I would assume new customers can also appear, the only way I can think of is to create a table for the sequences. You could just have a column for the customer code and int column for the sequence.

If your database needs these sequences really often (in scale of several per second), this could easily become a bottleneck, but I assume here that's not the case.