How to generate guid c #. NET in SQL Server

Source: Internet
Author: User

GUID (globally unified identifier) refers to the number generated on a machine, which ensures that all machines in the same time and space are unique. Generally, the platform provides APIs for generating guids. The generation algorithm is very interesting. It uses Ethernet Card addresses, nanoseconds, chip ID codes, and many possible numbers. The only drawback of GUID is that the generated result string is large ."
1. a guid is a 128-bit integer (16 bytes). When using a unique identifier, you can use this integer between all computers and networks.
2. The GUID format is "xxxxxxxx-xxxx-xxxxxxxxxxxx", where each x is a hexadecimal number in the range of 0-9 or a-f. For example, 337c7f2b-7a34-4f50-9141-bab9e6478cc8 is a valid GUID value.
3. No duplicate GUID value is generated on any two computers in the world (Koffer Note: it should be on the Earth. GUID is used to assign a unique identifier to a network or system with multiple nodes and computers.
4. On Windows, GUID is widely used: Registry, class and interface identification, database, or even automatically generated machine name and directory name.
GUID generated in SQL SERVER

The SQL Server Data Type uniqueidentifier can store a GUID value. You can useNEWID ()The function generates this value in SQL Server.

Generate GUID in. NET Program

The Guid structure is used to generate: Guid. NewGuid (). ToString (). Note that the method here isNewGuid ()Is different from the function name in the database. I made a mistake here, thinking that NewGuid () is also used in the database ()

C #
  1. Using System;
  2. Namespace ConAppLogTest
  3. {
  4. Public class Program
  5. {
  6. Static void Main (string [] args)
  7. {
  8. String guid = System. Guid. NewGuid (). ToString ();
  9. Console. WriteLine (guid );
  10. }
  11. }
  12. }

Output:

GUID: c4208862-c7fe-4d14-86d4-7bd5c55bd850
Press any key to continue...

Converts a string to a GUID.

C #
  1. String id = "c4208862-c7fe-4d14-86d4-7bd5c55bd850 ";
  2. Guid guid = System. Guid. Parse (id );
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.