Skip to content

Instantly share code, notes, and snippets.

@keith9820
Last active July 13, 2016 21:19
Show Gist options
  • Save keith9820/c6b214357fcf71552757 to your computer and use it in GitHub Desktop.
Save keith9820/c6b214357fcf71552757 to your computer and use it in GitHub Desktop.
Generate a random password in T-SQL
declare @idx as int
declare @randomPwd as nvarchar(64)
declare @rnd as float
select @idx = 0
select @randomPwd = N''
select @rnd = rand((@@CPU_BUSY % 100) + ((@@IDLE % 100) * 100) +
(DATEPART(ss, GETDATE()) * 10000) + ((cast(DATEPART(ms, GETDATE()) as int) % 100) * 1000000))
while @idx < 64
begin
select @randomPwd = @randomPwd + char((cast((@rnd * 83) as int) + 43))
select @idx = @idx + 1
select @rnd = rand()
end
select @randomPwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment