-
-
Save iradofurioso/b0ba0c904518cb6e09a08d2beb2e4e6f to your computer and use it in GitHub Desktop.
MySQL or MariaDB dirty solution to set UUID column as default
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
-- Some say MySQL already support UUID() function as default, but old versions and MariaDB not! | |
-- In case you deal with various tables create trigger to insert UUID is not a good solution from | |
-- a manteinance point of view. | |
-- DISCLAIMER 1: For learning purposes only. It is NOT secure setting a fixed value for UUID due to obvious reasons. | |
-- DISCLAIMER 2: Use char to store UUID is not a wise solution the correct approach is to use BINARY(16). I will keep | |
-- the below solution just for very small apps. | |
CREATE TABLE 'tb_test' ( | |
'id_test' INT NOT NULL AUTO_INCREMENT PRIMARY KEY | |
'uuid_test' char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', | |
'dt_created' datetime NULL DEFAULT NULL, | |
PRIMARY KEY ('id_test') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment