Subject | Re: [firebird-support] Need help in Firebird |
---|---|
Author | setysvar |
Post date | 2015-08-11T19:53:02Z |
>Dear All,of the data is a running serial number, 0 to 999999. I try the Count SQL
>I have a question. I need to store some data in Firebird database. One
function, but sometimes
>after INSERT function I get same number 2-3 times. After I try to makea tabel which contain an INTEGER field, and I update it, after I run a
QUERRY, but the situation
>is same.serial number (not recurring)?
>Could you give me a good sollution how can the DB make a running
>After each UPDATE I run a COMMIT.>Please give me an answer ASAP.
>The operating system is: Windows 7.
>Thank you very much!Hi Richard!
The reason you get the same number is most likely because of
simultaneous updates, i.e. that one transaction starts before the
previous transaction commits. COUNT have never been a reliable way of
getting a unique number. Moreover, COUNT will make things slow as the
table grows.
Rather, try:
CREATE SEQUENCE <MyPreferredSequenceName>
and then in your insert statement include
NEXT VALUE FOR <MyPreferredSequenceName>
If for some reason a transaction rolls back, that particular sequence
number is lost. Normally, this doesn't matter, but sometimes it may for
financial applications where laws say that there should be no
unexplained gaps.
HTH,
Set
PS! Your title "Need help in Firebird" is quite useless here, since
almost 50% of the emails fit that description (the other 50% are
answers). It would have been far better if it had been something like
"My numbers duplicate, I need them to be unique"