Skip to content

Instantly share code, notes, and snippets.

@floscher
Last active October 20, 2019 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save floscher/28ab5ee79052b09073d45219cf8002a1 to your computer and use it in GitHub Desktop.
Save floscher/28ab5ee79052b09073d45219cf8002a1 to your computer and use it in GitHub Desktop.
Add UUID column to MySQL table
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