Skip to content

Instantly share code, notes, and snippets.

@marsen
Last active December 23, 2015 23:49
Show Gist options
  • Save marsen/6712356 to your computer and use it in GitHub Desktop.
Save marsen/6712356 to your computer and use it in GitHub Desktop.
Auto Gen Random Keys by MSSQL
DECLARE @start INT = 1;
DECLARE @end INT = 50;
WITH #KEYS AS (
SELECT @start AS Number, REPLACE(LEFT(NEWID(), 18), '-', '') AS [KEY]
UNION ALL
SELECT Number + 1, REPLACE(LEFT(NEWID(), 18), '-', '') AS [KEY]
FROM #KEYS
WHERE Number < @end
)
SELECT * FROM #KEYS OPTION (MAXRECURSION 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment