A udf to generate passwords of given length @lenth--create a tally table for use in the viewcreate table dbo.numbers ( n int primary key)declare @n int; set @n = 1while @n <=1000begin insert dbo.numbers select @n set @n = @n+1end--create a view to expose NEWID() for randomnesscreate view dbo.vwRandomCharGeneratoras select top 1000 char(n) n from dbo.numbers where n between 65 and 90 or n between 97 and 122 --only A-Z or a-z characters order by newid()go--create password generator function which accepts length as inputcreate function dbo.udfPassWordGenerator (@length int)returns varchar(1000)ASbegindeclare @pwd char(1000)set @pwd = ''Select @pwd = n + @pwd from ( select n from dbo.vwRandomCharGenerator) dreturn left(@pwd,@length)endgo--call our password generator inline, passing in the desired lengthselect dbo.udfPassWordGenerator(10) pwd