A
A
Andrew2016-05-05 12:40:50
SQL
Andrew, 2016-05-05 12:40:50

SQL, id will increase in case of unsuccessful insertion, how to change this behavior?

If an error occurs during insertion, the id counter will still increase. Is there any way to change this behavior?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
wkololo_4ever, 2016-05-05
@wkololo_4ever

You can't, but you can use SEQUENCE instead of IDENTITY

D
Dmitry Kovalsky, 2016-05-05
@dmitryKovalskiy

You can do it, even wkololo_4ever showed you how, but sometimes it's better to understand the reasons for this behavior. If you make data imports sequential INSERT execution, then such things are extremely necessary to wrap in a transaction, and in case of an error, roll back the transaction and deal with the error.

A
Anton Agaltsov, 2016-05-05
@Archusha

Actually not how. If I'm not mistaken, this is protection against duplicated recording, under load.
Therefore, it is better to beat all this already in the logic of the program.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question