Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are sequential numbers necessary?

I am working on a winform (.NET) application which includes Orders, Invoices, Service Orders, Ticketing etc.

It it necessary for these enities to be sequential when numbering their IDs? IMO no. Take an order for instance, it can only be valid once it passes thorugh the business layer, during that proocess another order could've been created, approved and saved with the number 2 while the order which was created earlier with id 1 failed validation.

This seems to open a can of worms as to which layer assigns the order number, no?

Currently I am using non-sequential numbers prefixed with an identifier for the entity. Example, order uses OR-123. Is this a good idea?

Thanks

Related:

Database-wide unique-yet-simple identifiers in SQL Server

like image 414
Saif Khan Avatar asked Jun 08 '09 21:06

Saif Khan


3 Answers

You only need to have sequential ids if it is a valid business requirement.

like image 77
jonnii Avatar answered Sep 28 '22 01:09

jonnii


Sequential numbers are not necessary, and in some scenarios are a bad idea (in security-conscious systems where guessing is a problem). But it is relatively common to let the RDBMS handle this - most support an IDENTITY auto-incrementing type (although it gets more complex with multiple distributed master servers). Another option is Guid of course - little chance of duplicates.

The prefix approach is quite handy for quickly identifying numbers - but you can choose to just prepend the "OR-" at the layers above the db.

like image 26
Marc Gravell Avatar answered Sep 28 '22 01:09

Marc Gravell


Accounting and general ledger folks like sequential numbers and if the numbers are missing they want to know why. It is an accounting practice that if it is not done to specs can cost a business time and money.

like image 43
johnny Avatar answered Sep 28 '22 00:09

johnny