you're reading...
SQL Server

Random Password Generator

We have an environment with over 300 sql server instances and every 90 days we need to cycle “sa”. To help in this endeavor I created a script to generate random passwords. The passwords can be any length you require (while @idx < n). I use this script to generate a random password, reset “sa” and then write the new password out to an encrypted column in SQL Server.


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 < 8 –64
   select @randomPwd = @randomPwd + char((cast((@rnd * 83) as int) + 43))
   –PRINT @randomPwd –debug
   select @idx = @idx + 1
elect @rnd = rand()




About ldgaller

Accomplished Data Warehouse Architect, DBA and Software Architect with over 15 years of professional experience and demonstrated success designing and implementing solutions that improve business functionality and productivity. Highly diverse technical background with proven ability to design, develop and implement technology on an enterprise level. I approach all projects with passion, diligence, integrity, and exceptional aptitude.


No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: