How to generate a GUID or UUID without writing a program.

Quick reference for generating a GUID/UUID without writing a program. These examples are intended primarily for one-time generation. For high-throughput processing scenarios, consider a programmatic approach.

Generate a GUID/UUID in…

Throughout this guide, I use the terms GUID and UUID interchangeably. While the history of the two formats are different, they are essentially the same and technically interchangeable.

Command Line

Generate a GUID/UUID in a Linux Terminal

To generate a GUID/UUID in a Linux terminal, type uuidgen and press Enter. THe command will return a newly generated GUID/UUID.

NOTE: While the uuidgen command is widely available on most Linux distributions, it is not installed by default on all distributions. You may either need to install it, or use an alternative method to generate the value.

Linux uuidgen command

Linux uuidgen command

If you need the GUID/UUID in uppercase, you can use the tr (translate) command to convert the result to uppercase by typing uuidgen | tr [:lower:] [:upper:]

Generate a GUID/UUID in Windows PowerShell

To generate a GUID/UUID in PowerShell, open PowerShell, type New-Guid and press the Enter key. The new GUID/UUID will be output in the PowerShell window.

PowerShell NewGuid Command

PowerShell NewGuid Command

If you want just the GUID/UUID value, type (New-Guid).Guid.

If you want the GUID/UUID in an uppercase string instead of the default lowercase, type (New-Guid).ToString().ToUpper().

To generate the GUID/UUID and automatically copy it to the clipboard, type (New-Guid).Guid | Set-Clipboard.

Databases

Generate a GUID/UUID in MySQL

My examples for MySQL use MySQL Workbench. However, the queries are supported in any interface that supports running queries in MySQL.

To generate a GUID/UUID in MySQL, enter the query select uuid(); and run it. MySQL will return a new GUID/UUID value every time the query is run.

MySQL select uuid(); query

MySQL select uuid(); query

MySQL returns the GUID/UUID in lowercase format. If you need the GUID/UUID in uppercase format, then wrap uuid() in the upper() function. The query becomes select upper(uuid());, and the GUID/UUID will be returned in uppercase.

MySQL select upper(uuid()); query

MySQL select upper(uuid()); query

Generate a GUID/UUID in SQL Server

My examples for SQL Server use SQL Server Management Studio (SSMS). However, the queries are supported in any interface that supports running queries in SQL Server.

To generate a GUID/UUID in SQL Server, enter the query select newid() and run it. SQL Server will return a new GUID/UUID value every time the query is run.

SQL Server select newid() query

SQL Server select newid() query

If you need a lowercase formatted GUID/UUID, then wrap newid() in the lower() function. The query becomes select lower(newid()), and the GUID/UUID will be returned in lowercase.

SQL Server select lower(newid()) query

SQL Server select lower(newid()) query

IDEs and Code Editors

Generate a GUID/UUID in Visual Studio IDE

To generate a GUID/UUID in Visual Studio, click the Tools menu and then click the Create GUID menu option. The Create GUID dialog box will display.

Visual Studio Create GUID Dialog

Visual Studio Create GUID Dialog

The Visual Studio Create GUID dialog supports creating the GUID in 6 formats. The supported formats are very Windows specific. Visual Studio is lacking an option to simply create a GUID/UUID as a plain string with no wrapping characters. The easiest way to get as close as possible to the simplified format is to choose the Registry Format, click the Copy button, and then remove the curly braces from the beginning and end. You may also need to use a text editor to convert the upper case characters to lower case if the environment in which you need the generated value has set lowercase values as the standard.

Generate a GUID/UUID in Visual Studio Code

Generate a GUID/UUID in Visual Studio Code with an extension

Visual Studio Code is, by default, a source code editor with limited out-of-the-box functionality. It relies on extensions for customization. Generating a GUID/UUID in Visual Studio Code isn’t supported by default, but there are many extensions that do support GUID/UUID generation. One such extension is called Insert GUID ​. I’ve installed the extension in my version of Visual Studio Code. Once installed, I can press Ctrl + Shift + P to open the command palette. In the command field, I can type insert guid and click on the available command option. Clicking on that option gives me similar options to those available in Visual Studio.

Visual Studio Code: Insert GUID Extension Options

Visual Studio Code: Insert GUID Extension Options

One nice thing about the Visual Studio Code Insert GUID extension is that, unlike Visual Studio, the generated GUID/UUID is provided in lower case. This is how I prefer to see GUID/UUID values, as it is the more commonly used format across the industry as a whole.

The casing of the GUID/UUID does not matter. A GUID/UUID value is a 128-bit value, represented by hexadecimal characters. So, A and a are the same value, B and b are the same, etc. Just be consistent if you can. However, it is possible to see systems with many external partners exchanging data to see a mix of both. This is perfectly acceptable and causes no problems from a technical perspective.

Another nice thing about the Insert GUID extension is that the first option is just the GUID/UUID alone, without any additional delimiters or other data elements.

Generate a GUID/UUID in Visual Studio Code using a terminal session

An extension isn’t really necessary in Visual Studio Code, as you can just use the integrated terminal to access the operating system’s already existing utilities for creating a GUID/UUID. On Windows, for example, you can just open a PowerShell terminal and follow the instructions for generating a GUID/UUID in PowerShell . On Linux, open a terminal in Visual Studio Code and follow the instructions for generating a GUID/UUID in Linux .

Final Thoughts

Generating a GUID/UUID is very easy to do using what I would consider generally available tools for most developers. For one-off GUID/UUID generation, there is usually no reason to write a program. If one of the methods of generating a GUID/UUID discussed in this article isn’t available to you, it may be worth checking to see if one of the tools that you already use has the capability to generate one.


The postings on this site are my own and do not necessarily reflect the views of my employer.

The content on this blog is for informational and educational purposes only and represents my personal opinions and experience. While I strive to provide accurate and up-to-date information, I make no guarantees regarding the completeness, reliability, or accuracy of the information provided.

By using this website, you acknowledge that any actions you take based on the information provided here are at your own risk. I am not liable for any losses, damages, or issues arising from the use or misuse of the content on this blog.

Please consult a qualified professional or conduct your own research before implementing any solutions or advice mentioned here.