Monday, March 26, 2012

Multiple insert with the same ID

Here is my problem:

I would like to execute 10 inserts and every insert in this batch should have the same ID. The next batch would have the next sequential number (ID) and so on...

I can do this by using a secondary table where I keep track of my IDs.

Is there another way of doing it?

Thanks.

dgYou could dynamically generate something based off something like the customer ID and the milliseconds of the date, for example. Not guaranteed to be unique, but some sort of thing based on your data that might be. You could also use the NEWID function to create a guaranteed unique value, but then you'd be using more space to store it than if using an int. Or, just select the max existing value before you do the insert, but you might get a collision there depending on activity. Some ideas

No comments:

Post a Comment