Guid uuid generation primary key policy

Source: Internet
Author: User
Tags table definition

GUID (Global unique identifier) is a globally unique identifier, which consists of the ID numbers on the NIC (each Nic has a unique ID number) and a 16-byte binary value generated by the unique number of the CPU clock.

The GUID format is "xxxxxxxx-xxxx-xxxxxxxxxxxx", where each x is a hexadecimal number in the range of 0-9 or a-f. Example: 76895313-839E-4E89-BAFC-B253BFF3173F

No two computers in the world will generate duplicate GUID values. GUID is used to assign a unique identifier to a network or system with multiple nodes and computers. On Windows, GUID is widely used: Registry, class and interface identifiers, databases, and even automatically generated machine names and directory names.

1. SQL Server database
Previously, the SQL Server database specified the column type as uniqueidentifier In the table definition, and the column value is of the GUID type.

2. Produce a GUID using a T-SQL
Insert into table1 (id, name,...) values (NewID (), 'zhang san ',...)

3. Create a GUID in C #
Guid guid = Guid. NewGuid ();
Console. Writeln (guid. ToString ());

4. Create a UUID in Java
Only by checking information on the internet can we know that in Java, UUID is changed. The creation method is also surprisingly simple
 
System. out. println (java. util. UUID. randomUUID ());

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.