Create order GUID based on SQL Server collation

Source: Internet
Author: User

  Public Static classGuidutil {Private Static ReadOnly LongEpochmilliseconds =NewDateTime (1970,1,1,0,0,0, DATETIMEKIND.UTC). Ticks/10000L; /// <summary>        ///creates a sequential GUID according to SQL Server ' s ordering rules. /// </summary>         Public StaticGuid newsequentialid () {//This code is not reviewed to guarantee uniqueness under most conditions, nor completely optimize for avoiding //page splits in SQL Server when doing inserts from the multiple hosts, so does not re-use in production systems.            varGuidbytes =Guid.NewGuid ().            Tobytearray (); //get the milliseconds since Jan 1 1970            byte[] sequential = Bitconverter.getbytes ((DateTime.Now.Ticks/10000L) -epochmilliseconds); //Discard the 2 most significant bytes, as we have care about the milliseconds increasing, but the highest ones //should is 0 for several thousand years to come (non-issue).            if(Bitconverter.islittleendian) {guidbytes[Ten] = sequential[5]; guidbytes[ One] = sequential[4]; guidbytes[ A] = sequential[3]; guidbytes[ -] = sequential[2]; guidbytes[ -] = sequential[1]; guidbytes[ the] = sequential[0]; }            Else{buffer.blockcopy (sequential,2, Guidbytes,Ten,6); }            return NewGuid (guidbytes); }    }

Create order GUID based on SQL Server collation

Related Article

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.