Create Random Word to obfuscate a SQL Column
2
votes
1
answer
4755
views
Does anyone have any SQL code to automatically generate words (all letter, no number).
Is there any inline SQL to perform this on a column?
We are trying to obfuscate first/last name and other word columns in table.
[This answer](https://stackoverflow.com/questions/2152204/tsql-pseudo-random-text-generator) currently does not work on column, because it generates the same result within a column.
select top (@stringlength) char(abs(checksum(newid())) % 26 + ascii('A'))
from sys.all_objects
for xml path('')
I tried this, but functions are slow, inline queries can be faster, feel free to improve or rewrite below
CREATE VIEW [dbo].[RandomValueVw]
AS
SELECT RAND() as random_value
CREATE function dbo.RandomWordGenerate(@length int)
returns varchar(50)
as begin
DECLARE
@text nvarchar(255),
@i int
SET @i = 0
SET @text = ''
WHILE (@i < @length)
BEGIN
SET @text = @text + CHAR((select * from [dbo].[RandomValueVw]) * 26 + 65)
SET @i = @i + 1
END
return @text
end
Asked by user129291
May 2, 2018, 10:27 PM
Last activity: Apr 4, 2019, 03:32 PM
Last activity: Apr 4, 2019, 03:32 PM