The order number has 3 attributes: 1. Uniqueness 2. Non-speculative 3. Efficiency
Uniqueness is one of the most important, it is meaningless to repeat the order number. The second is efficiency, repeatedly looking for a database will be slow to generate!
Irregular order number Generation ideas: System.currenttimemillis () + several random numbers, OK. System.currenttimemillis () This number generally does not appear to be the same.
In some companies ' internal systems, we may be asked to give a sequential order number for a rule, such as: month Date + (current order number +1), special string + (current order number +1). Because two people at the same time operation will be the same order number, then in order to ensure the uniqueness of the order number, you can not query the database to find the current number of orders (very likely two users in the same period to check the database, that is the same order, no use!) )。 So, create a single table in the data to create a current order number (Currentindentnum) with an initial value of 0.
Specific database design: INDENTTB:
Indentid
Indent
CurrentTime initial value set to GETDATE ()
Ifuse
CURRENTINDENTNUMTB:
Currentindentnumid
Currentindentnum
In the database stored procedure, use:
Update CURRENTINDENTNUMTB
BEGIN Tran
Set currentindentnum=currentindentnum+1
Select Currentindentnum
From CURRENTINDENTNUMTB
Commit Tran
(Begin tran .... COMMIT Tran when a transaction has an exception, roll back to the execution of the transaction)
To ensure the uniqueness of the order.
Specific implementation: In the Load event or $ (document), the above procedure is performed to return the current number of orders to the page. If the order is canceled, the Mark Ifuse is false.
Generation of order numbers