Skip to main content

How to Create UUID in SQL Server

Complete guide with NEWID() and NEWSEQUENTIALID()

How to Create UUID in SQL Server. Call NEWID() to generate a SQL Server UUID in one line. Older servers need an extension before any generation function works, and a postgresql uuid page lists those alternatives.

Generate UUID for SQL Server

SELECT NEWID();
550E8400-E29B-41D4-A716-446655440000

When you need a globally unique identifier for a SQL Server table, the built-in NEWID() function generates a random GUID in one call, with no extension or install required. Store it in the native UNIQUEIDENTIFIER type — 16 raw bytes instead of a 36-character string — so joins and index lookups stay fast as your tables grow. Below you'll find copy-paste ready T-SQL for generating a SQL Server UUID, casting a string back into a UNIQUEIDENTIFIER, and the sequential alternative that keeps a clustered index from fragmenting under heavy inserts.

How to Generate a UUID in SQL Server

The simplest way to generate a UUID in SQL Server is the built-in NEWID() function, which produces a random, RFC 4122-compliant UNIQUEIDENTIFIER value with no extensions or setup required. Because the output is reproducible, a uuid v5 generator removes the need for a lookup table linking names to identifiers.

T-SQL
-- Generate a random UUID directly
SELECT NEWID();
-- Output: 550E8400-E29B-41D4-A716-446655440000

-- Use it as a column default
CREATE TABLE Users (
    Id UNIQUEIDENTIFIER DEFAULT NEWID() PRIMARY KEY,
    Email NVARCHAR(255)
);

Explanation

Convert a String to a UUID in SQL Server

A UUID sent as a string — from an API request or an application layer — needs to be converted to SQL Server's native UNIQUEIDENTIFIER type before it can be compared or stored efficiently. In a mongosh session, a mongodb uuid is stored as BSON Binary subtype 4, and the page shows it printed in hyphenated form.

T-SQL
-- CAST: standard ANSI SQL style
SELECT CAST('550e8400-e29b-41d4-a716-446655440000' AS UNIQUEIDENTIFIER);

-- CONVERT: SQL Server-specific, supports a style argument
SELECT CONVERT(UNIQUEIDENTIFIER, '550e8400-e29b-41d4-a716-446655440000');

Explanation

Other Options for Generating UUIDs in SQL Server

NEWID() covers most use cases, but SQL Server also ships NEWSEQUENTIALID() for tables where insert performance matters more than unpredictability.

T-SQL
-- NEWSEQUENTIALID() can ONLY be used as a column default
CREATE TABLE Orders (
    Id UNIQUEIDENTIFIER DEFAULT NEWSEQUENTIALID() PRIMARY KEY,
    CustomerId UNIQUEIDENTIFIER NOT NULL
);

-- Calling it directly like NEWID() is not allowed:
-- SELECT NEWSEQUENTIALID(); -- fails

Explanation

About the author

Vinitha Pu

Founder and designer

Vinitha Pu is a graphic designer based in Palakkad, Kerala, who builds free, privacy-friendly browser tools. She studied Textile and Apparel Design at Avinashilingam University and completed a C-Tech in Graphic Design at Image Creative Education in 2025. She designs, builds and maintains the UUID generators, validator, decoder and the language and database UUID guides on UUID Generator.

  • Content author: Vinitha Pu
  • Fact checked by: Vinitha Pu. Every generator is checked against the RFC 4122 and RFC 9562 layouts and every code example is run before it goes live.
  • Published Updated

Vinitha Pu on Behance · Vinitha Pu on LinkedIn

Comments & Feedback

Share your experience or ask questions about this tool

Copied!