Last active
October 20, 2019 15:38
-
-
Save floscher/28ab5ee79052b09073d45219cf8002a1 to your computer and use it in GitHub Desktop.
Add UUID column to MySQL table
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
ALTER TABLE `table_name` ADD COLUMN `uuid` binary(16); | |
# Each value must be different, see https://stackoverflow.com/a/54777792 | |
UPDATE `table_name` SET `uuid` = (SELECT UNHEX(REPLACE(UUID(), _utf8'-', _utf8''))); | |
ALTER TABLE `table_name` MODIFY `uuid` binary(16) NOT NULL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment