Generating random strings with T-SQL

Scott Lawrence picture Scott Lawrence · Aug 24, 2009 · Viewed 195.8k times · Source

If you wanted to generate a pseudorandom alphanumeric string using T-SQL, how would you do it? How would you exclude characters like dollar signs, dashes, and slashes from it?

Answer

Stefan Steinegger picture Stefan Steinegger · Aug 24, 2009

Using a guid

SELECT @randomString = CONVERT(varchar(255), NEWID())

very short ...