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

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from .Net Core Training in Chennai. or learn thru .Net Core Training in Chennai. Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Es6 Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete