What is a GUID?
A GUID (Globally Unique Identifier) is a 128-bit number used to uniquely identify resources in computer systems. GUIDs are identical to UUIDs and follow the same RFC-4122 standard.
The term "GUID" is predominantly used in Microsoft technologies:
- .NET Framework and .NET Core - using
System.Guid
- SQL Server -
uniqueidentifier data type
- COM and Windows API - component identification
- Active Directory - object identifiers
GUID Format
A GUID is displayed as 32 hexadecimal digits in 5 groups separated by hyphens:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Example: 550e8400-e29b-41d4-a716-446655440000
GUID in C# / .NET
// Generate a new GUID
Guid newGuid = Guid.NewGuid();
// Parse from string
Guid parsed = Guid.Parse("550e8400-e29b-41d4-a716-446655440000");
// Safe parsing
if (Guid.TryParse(input, out Guid result)) {
// Use result
}
GUID in SQL Server
-- Generate a new GUID
SELECT NEWID();
-- Create table with GUID primary key
CREATE TABLE Users (
Id UNIQUEIDENTIFIER DEFAULT NEWID() PRIMARY KEY,
Name NVARCHAR(100)
);
-- For better index performance, use NEWSEQUENTIALID()
CREATE TABLE Orders (
Id UNIQUEIDENTIFIER DEFAULT NEWSEQUENTIALID() PRIMARY KEY,
OrderDate DATETIME
);
Frequently Asked Questions
What is a GUID?
GUID (Globally Unique Identifier) is a 128-bit identifier used primarily in Microsoft technologies. GUIDs are identical to UUIDs (Universally Unique Identifiers) and follow the same RFC-4122 standard. The term GUID is commonly used in .NET, SQL Server, and Windows development.
What is the difference between GUID and UUID?
GUID and UUID are the same thing - both are 128-bit identifiers following RFC-4122. The term GUID is used in Microsoft ecosystems (.NET, SQL Server, COM), while UUID is the standard term used in other contexts like databases, APIs, and cross-platform development.
How do I use a GUID in C# or .NET?
In C#, use Guid.NewGuid() to generate a new GUID. Example: Guid myGuid = Guid.NewGuid(); You can also parse a GUID string using Guid.Parse() or Guid.TryParse() for safe parsing.
How do I create a GUID in SQL Server?
In SQL Server, use the NEWID() function to generate a GUID. For sequential GUIDs (better for indexing), use NEWSEQUENTIALID() as a column default.