Monday, August 2, 2010

MS-SQL - Generate 8 Digit Random Alpha Numeric Password in MS-SQL

First create a view like this:


   1:  CREATE VIEW GetPassword
   2:  AS
   3:      SELECT LOWER(LEFT(NEWID(),8)) as GenPassword
Execute this above view in database

Then create a function like this:

   1:  CREATE FUNCTION Dbo.GeneratePassword()
   2:  RETURNS NVARCHAR(10)
   3:  AS
   4:      BEGIN
   5:          DECLARE @Password NVARCHAR(10)
   6:              SET @Password=(SELECT GenPassword from GetPassword)
   7:              
   8:                  RETURN(@Password)
   9:      END
Execute this above funtion in database

Calling Function:

   1:  SELECT dbo.GeneratePassword() as Password

Download
Download Script

No comments:

Post a Comment