mysqlsqlsanitizationanonymize

What's the most efficient way of truncating the names in a first_name and last_name column to 1 character?


What's the most efficient way of truncating the names in a first_name and last_name column to 1 character?

I have a mysql database that I want to hand off to a developer but I want to partially sanitize the data so that the two name records drop down to just initials.

I tried to modify the varchar to 1 character but mysql will not let me truncate the data, it just throws an error. I am working from a dump of the database before I hand it off. I want to obscure the names without making them all the same.


Solution

  • update tablename set first_name=left(first_name, 1), last_name = left(last_name, 1)
    

    But, as Gordon Linoff mentioned, this could be expensive if you have a lot of rows in the table