Generate New (uniqueidentifier) in SQL Server

If you want to generate a new uniqueidentifier in SQL you can simply use the NEWID() function

       -- Example 1
       SELECT NEWID()

       -- Example 2       
       DECLARE @EmployeeID uniqueidentifier
       SET @EmployeeID = NEWID()

       -- Example 3
       INSERT INTO Employees(EmployeeID, Name)
       VALUES (NEWID(), 'msm2020')

       -- Example 1
       SELECT NEWID()

       -- Example 2       
       DECLARE @EmployeeID uniqueidentifier
       SET @EmployeeID = NEWID()

       -- Example 3
       INSERT INTO Employees(EmployeeID, Name)
       VALUES (NEWID(), 'msm2020')
  1. <code>
  2. -- Example 1
  3. SELECT NEWID()
  4. -- Example 2
  5. DECLARE @EmployeeID uniqueidentifier
  6. SET @EmployeeID = NEWID()
  7. -- Example 3
  8. INSERT INTO Employees(EmployeeID, Name)
  9. VALUES (NEWID(), 'msm2020')
  10. </code>
<code>
       -- Example 1
       SELECT NEWID()

       -- Example 2       
       DECLARE @EmployeeID uniqueidentifier
       SET @EmployeeID = NEWID()

       -- Example 3
       INSERT INTO Employees(EmployeeID, Name)
       VALUES (NEWID(), 'msm2020')

</code>

Popular posts from this blog

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=xx.0.0.0, Culture=neutral, PublicKeyToken='xxx' or one of its dependencies.

C# Crop white space from around the image

The specified version string contains wildcards, which are not compatible with determinism.