Last active
March 30, 2023 10:52
-
-
Save slava-konashkov/f20edbd504febd4e578ff877b2778761 to your computer and use it in GitHub Desktop.
Anonymizing and masking sensitive data in SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Random Int | |
SELECT FLOOR(RAND() * 100); | |
-- Random float | |
select FLOOR(RAND() * 1000 ) + round(rand() * 0.49 + 0.01, 2); | |
-- Random Srting | |
SELECT MD5(RAND()); | |
SELECT TO_BASE64(UNHEX(HEX(MD5(RAND())))); | |
-- Random Srting with random length | |
SELECT SUBSTR(MD5(RAND()), 1, FLOOR(RAND() * 12) + 1); | |
SELECT SUBSTRING(TO_BASE64(UNHEX(HEX(MD5(RAND())))) FROM 1 FOR FLOOR(RAND() * 10) + 1); | |
-- Random char | |
SELECT substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ', rand()*26+1, 1); | |
-- get domain from email | |
SELECT SUBSTRING_INDEX(email, '@', -1); | |
-- random email | |
SELECT CONCAT(SUBSTR(MD5(RAND()), 1, FLOOR(RAND() * 12) + 1), '@', SUBSTRING_INDEX(email, '@', -1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment