Generation of order numbers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.