What is a GUID?
A GUID (Globally Unique Identifier) is Microsoft's implementation of the UUID (Universally Unique Identifier) standard. GUIDs and UUIDs are technically identical—both are 128-bit identifiers represented as 32 hexadecimal digits. The term "GUID" is predominantly used in the Microsoft ecosystem, including .NET, C#, Visual Studio, SQL Server, and Windows development.
Microsoft's Guid.NewGuid() in .NET generates version 4 (random) GUIDs using a cryptographically secure random number generator, making them suitable for most applications requiring unique identifiers.
GUID vs UUID: The Difference
GUID (Microsoft)
- • Typically displayed UPPERCASE
- • Often wrapped in {braces}
- • Used in .NET, C#, SQL Server
- • Windows Registry uses GUIDs
UUID (Standard)
- • Typically displayed lowercase
- • No braces, just hyphens
- • Used everywhere else
- • Defined by RFC 4122
Bottom line: They're the same thing with different naming conventions. A GUID generated in C# will work anywhere a UUID is expected.
.NET GUID Format Specifiers
In C# and .NET, the Guid.ToString() method accepts format specifiers:
| Format | Specifier | Example Output |
|---|---|---|
| Standard (Default) | "D" | 00000000-0000-0000-0000-000000000000 |
| Braces ★ | "B" | {00000000-0000-0000-0000-000000000000} |
| No Hyphens | "N" | 00000000000000000000000000000000 |
| Parentheses | "P" | (00000000-0000-0000-0000-000000000000) |
| Hexadecimal | "X" | {0x00000000,0x0000,...} |
★ The "B" (braces) format is commonly used in Windows Registry, COM/OLE programming, and configuration files.
Generate GUIDs in Code
// Generate new GUID
Guid guid = Guid.NewGuid();
// Different output formats
Console.WriteLine(guid.ToString("D")); // 550e8400-e29b-41d4-a716-446655440000
Console.WriteLine(guid.ToString("B")); // {550e8400-e29b-41d4-a716-446655440000}
Console.WriteLine(guid.ToString("N")); // 550e8400e29b41d4a716446655440000
Console.WriteLine(guid.ToString("P")); // (550e8400-e29b-41d4-a716-446655440000)
// Parse GUID from string
Guid parsed = Guid.Parse("{550e8400-e29b-41d4-a716-446655440000}");
// Empty/Nil GUID
Guid empty = Guid.Empty; // 00000000-0000-0000-0000-000000000000
# Generate new GUID
$guid = [guid]::NewGuid()
Write-Host $guid
# Alternative method
$guid = New-Guid
Write-Host $guid
# Format with braces
Write-Host $guid.ToString("B")
# Generate multiple GUIDs
1..10 | ForEach-Object { [guid]::NewGuid() }
-- Generate new GUID (random, like UUID v4)
SELECT NEWID();
-- Generate sequential GUID (better for indexes)
SELECT NEWSEQUENTIALID(); -- Only in DEFAULT constraint
-- Use as primary key
CREATE TABLE Users (
Id UNIQUEIDENTIFIER DEFAULT NEWID() PRIMARY KEY,
Email NVARCHAR(255) NOT NULL
);
-- Insert with auto-generated GUID
INSERT INTO Users (Email) VALUES ('[email protected]');
' Generate new GUID
Dim guid As Guid = Guid.NewGuid()
Console.WriteLine(guid.ToString())
' With braces format
Console.WriteLine(guid.ToString("B"))
Common GUID Use Cases in Microsoft Ecosystem
SQL Server Primary Keys
GUIDs are commonly used as primary keys in SQL Server, especially in distributed databases and replication scenarios.
Tip: Use NEWSEQUENTIALID() for better index performance than NEWID().
Windows Registry
COM classes, application identifiers, and many Windows settings use GUIDs in {braces} format.
Example: {12345678-1234-1234-1234-123456789012}
.NET Entity IDs
Entity Framework and other ORMs use GUIDs for entity identifiers, enabling offline ID generation.
Generate IDs client-side before database insert.
Azure Resources
Azure uses GUIDs extensively for subscription IDs, resource IDs, tenant IDs, and correlation IDs.
Essential for Azure CLI, PowerShell, and ARM templates.
SQL Server: NEWID() vs NEWSEQUENTIALID()
| Feature | NEWID() | NEWSEQUENTIALID() |
|---|---|---|
| Generation | Random (UUID v4) | Sequential |
| Index Performance | Poor (fragmentation) | Good (sequential inserts) |
| Usage | Anywhere | Only in DEFAULT constraint |
| Predictability | Unpredictable | Partially predictable |
💡 Recommendation
For SQL Server primary keys, use NEWSEQUENTIALID() in the DEFAULT constraint for better performance. If you need to generate GUIDs in application code or need unpredictability, use NEWID() or C#'s Guid.NewGuid(). For new projects, also consider UUID v7 which is time-sorted.
Related Tools
Frequently Asked Questions
Is a GUID the same as a UUID?
Yes, they are technically identical. Both are 128-bit identifiers. "GUID" is the term used by Microsoft, while "UUID" is the standard term used everywhere else. A GUID generated in C# is fully compatible with UUID libraries in Python, Java, or any other language.
What UUID version does Guid.NewGuid() generate?
.NET's Guid.NewGuid() generates version 4 (random) UUIDs using a cryptographically secure random number generator. This is the same as UUID v4.
Should I use NEWID() or NEWSEQUENTIALID() in SQL Server?
For primary keys, use NEWSEQUENTIALID() in the DEFAULT constraint—it generates sequential GUIDs that improve index performance. Use NEWID() when you need GUIDs outside of DEFAULT constraints or when unpredictability is important.
Why does Microsoft use braces around GUIDs?
The {braces} format originated with COM (Component Object Model) in the early 1990s. It became the de facto standard in Windows Registry, Visual Studio project files, and many Microsoft tools. While not technically required, it helps visually distinguish GUIDs from other hexadecimal strings.