Friday, June 15, 2012

Easy way to generate random character string for password in SQL Server


Hi Friends!

I was searching for generating random character string for password in SQL Server and goggled a lot.

I have found various stored procedures and functions to generate random character password (it was really big procedures/functions !!)  So I have given a thought and an idea strike on my mind and then I have found following, the most simplest way to generate random character string of password.

SELECT 
LEFT(UPPER(NEWID()), 2) + 
LEFT(LOWER(NEWID()), 2) + 
LEFT(UPPER(NEWID()), 2) + 
LEFT(LOWER(NEWID()), 2)

The above is very basic form to generate random character string for password. you can customize this according to your requirement (like variable password length and etc.)

Happy Programming :)