Anonymize varchar column Sybase Ase

34 Views Asked by At

How to do anonymization in a varchar column in Sybase ASE ? I want to use the update query

The column is already fulfilled and I just want to anonymize the column with random characters.

Thanks in advance.

Best regards.

1

There are 1 best solutions below

0
3N1GM4 On

Setting up some example data:

create table #yourTable
(
    yourColumn varchar(32)
)

insert into #yourTable values
('John Smith'),
('Sarah Jones'),
('Phillip Baker'),
('Faye Johnson')

You can use newid() and some string maniuplation functions to generate a random string of characters, for example with a length of 8:

update #yourTable 
set yourColumn = SUBSTRING(REPLACE(CAST(NEWID() AS VARCHAR(255)),'-',''), 1, 8)

If you want to more or less guarantee uniqueness of the values and/or need to maintain some kind of relational nature of them, you can use the whole GUID (as long as your target field is at least 32 characters wide):

update #yourTable 
set yourColumn = REPLACE(CAST(NEWID() AS VARCHAR(255)),'-','')