As I pointed out the sequence table is ugly and only works for a single insert. It should only be done when there are interactive inserts done by users. It's useless, as you pointed out, if any set based inserts are going on.
There is a major POS system on the market that I support that uses this type of insert logic and it performs quite well. One insert per cash register per customer standing in line. There was another one where only 1 person in the company did invoicing and it worked well.
The application in question here was adding employees. That seems to be something that would be done one employee at a time.
Other than these types of applications I totally agree with you. It's ugly, not set based and prone to dead locks.
Ah... but as I said... you CAN do batch inserts with a Sequence table instead of RBAR... it's just a pain compared to the straight forward method of using an IDENTITY column.
The other thing that I'm trying to nicely point out is that any code that uses a sequence table where you have to provide columnar inputs to a single row is really asking for trouble because now you have an even more concentrated hotspot and requires the very definition of the table to change if you add more "countries". Whether those are the cards that have been dealt to you or not, I don't want anyone to think that's even close to the right way of doing it even if a POS 3rd party bit of software is involved.
is pronounced ree-bar and is a Modenism for R
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Helpful Links:
How to post code problemsHow to post performance problemsForum FAQs