How to Generate GUIDs in SQL Server

Generate GUIDs in SQL Server with built-in database functions such as NEWID() and NEWSEQUENTIALID(). When you are writing queries or defaults, T-SQL is the usual way to work with those values.

Important: NEWSEQUENTIALID() is not GUID v7. It is a SQL Server-specific sequential GUID strategy, not the RFC 9562 time-ordered format.

How to generate random GUIDs in SQL Server

SQL Server generates random GUIDs with NEWID(). In practice, you usually call it from T-SQL in a query, default constraint, or stored procedure.

T-SQL example

SELECT NEWID() AS GuidV4LikeValue;

This is the standard SQL Server way to generate a random uniqueidentifier.

How to generate time-ordered GUID alternatives in SQL Server

SQL Server exposes NEWSEQUENTIALID() for SQL Server-friendly ordered inserts. It is a database-specific sequential GUID feature, not RFC 9562 GUID v7.

T-SQL example

CREATE TABLE dbo.Example
(
    Id uniqueidentifier NOT NULL DEFAULT NEWSEQUENTIALID(),
    Name nvarchar(100) NOT NULL
);

Use NEWSEQUENTIALID() when you want SQL Server-friendly insert ordering, but do not document it as GUID v7.

How to parse and format GUIDs in SQL Server

SQL Server stores GUIDs as uniqueidentifier. When you need to convert between text and uniqueidentifier, you normally do it in T-SQL with TRY_CONVERT() or CONVERT().

T-SQL example

DECLARE @guidText nvarchar(36) = '550e8400-e29b-41d4-a716-446655440000';
DECLARE @guid uniqueidentifier = TRY_CONVERT(uniqueidentifier, @guidText);

SELECT @guid AS ParsedGuid,
       CONVERT(char(36), @guid) AS GuidText;

Use TRY_CONVERT(uniqueidentifier, ...) when the input may be invalid and CONVERT(char(36), ...) when you need a string result in T-SQL.

Native support notes

  • SQL Server uses GUID terminology in documentation and developer workflows.
  • NEWID() is the common random GUID generator.
  • NEWSEQUENTIALID() improves locality but is not equivalent to GUID v7.
  • If you truly need RFC-compliant GUID v7, generate it in the application layer and store it in uniqueidentifier.

Practical notes

  • For random identifiers, GUID v4 remains the closest conceptual match.
  • For ordered inserts, SQL Server-specific sequential GUIDs may still be more practical than random GUIDs.
  • Read database performance guidance before choosing clustered keys.

Frequently Asked Questions

In practical SQL Server usage, NEWID behaves like the usual random GUID choice, but SQL Server documentation does not label it as RFC UUID v4 in everyday APIs.

No. SQL Server has sequential GUID features, but they are not native GUID v7 implementations.

NEWSEQUENTIALID() is SQL Server-specific and improves insert locality, but it is not RFC 9562 GUID v7. If you document it as v7, you blur portability, interoperability, and ordering expectations across databases and application code.

Learn more

These articles expand on related concepts, formats and practical considerations.

By using this site, you agree to our Privacy Policy and Terms of Service. You are not permitted to use the GUIDs (also known as UUIDs) generated by this site or use any other content, services and information available if you do not agree to these terms.
Disclaimer: All information is provided for general educational and technical reference only. While we aim to keep the content accurate, current and aligned with published standards, no guarantees are made regarding completeness, correctness or suitability for any specific use case.
GUID specifications, best practices, security guidance, database behavior and ecosystem conventions (including cloud platforms and identifier formats) may change over time or differ by implementation. Examples, recommendations and comparisons are illustrative and may not apply universally.
This content should not be considered legal, security, compliance or architectural advice. Before making critical design, security or production decisions, always consult the latest official standards and vendor-specific documentation.
Always evaluate behavior in your own environment.
Standards Compliance: The GUIDs generated by this site conform to RFC 4122 and RFC 9562 specifications whenever possible, using cryptographically secure random number generation.