MySQL column that auto generates data, longer than UUID












0















My friend has the problem as shown below. He asked at StackOverFlow and there is no reply yet till now so I wish to help him to try the luck here. Thanks for everyone that helps.



"I would like to ask if its possible to set up a database table that has a column that auto generates random alphanumerical data that is longer that what UUID can do. I've been using UUID for a while now but I would like to have a longer string of random data in my columns, something similar to that of a token authenticator (around 300+ characters). So when I insert values in columns, this particular column will auto generate data by itself. Thanks in advance."



Quoted from Reuben Tan
Source: https://stackoverflow.com/questions/43461771/mysql-column-that-auto-generates-data-longer-than-uuid










share|improve this question
















bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • When you first insert the row? Or whenever you update the row, too?

    – Rick James
    Apr 19 '17 at 1:24
















0















My friend has the problem as shown below. He asked at StackOverFlow and there is no reply yet till now so I wish to help him to try the luck here. Thanks for everyone that helps.



"I would like to ask if its possible to set up a database table that has a column that auto generates random alphanumerical data that is longer that what UUID can do. I've been using UUID for a while now but I would like to have a longer string of random data in my columns, something similar to that of a token authenticator (around 300+ characters). So when I insert values in columns, this particular column will auto generate data by itself. Thanks in advance."



Quoted from Reuben Tan
Source: https://stackoverflow.com/questions/43461771/mysql-column-that-auto-generates-data-longer-than-uuid










share|improve this question
















bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • When you first insert the row? Or whenever you update the row, too?

    – Rick James
    Apr 19 '17 at 1:24














0












0








0








My friend has the problem as shown below. He asked at StackOverFlow and there is no reply yet till now so I wish to help him to try the luck here. Thanks for everyone that helps.



"I would like to ask if its possible to set up a database table that has a column that auto generates random alphanumerical data that is longer that what UUID can do. I've been using UUID for a while now but I would like to have a longer string of random data in my columns, something similar to that of a token authenticator (around 300+ characters). So when I insert values in columns, this particular column will auto generate data by itself. Thanks in advance."



Quoted from Reuben Tan
Source: https://stackoverflow.com/questions/43461771/mysql-column-that-auto-generates-data-longer-than-uuid










share|improve this question
















My friend has the problem as shown below. He asked at StackOverFlow and there is no reply yet till now so I wish to help him to try the luck here. Thanks for everyone that helps.



"I would like to ask if its possible to set up a database table that has a column that auto generates random alphanumerical data that is longer that what UUID can do. I've been using UUID for a while now but I would like to have a longer string of random data in my columns, something similar to that of a token authenticator (around 300+ characters). So when I insert values in columns, this particular column will auto generate data by itself. Thanks in advance."



Quoted from Reuben Tan
Source: https://stackoverflow.com/questions/43461771/mysql-column-that-auto-generates-data-longer-than-uuid







mysql uuid google-cloud-sql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 23 '17 at 12:40









Community

1




1










asked Apr 19 '17 at 1:00









Tan Yih WeiTan Yih Wei

11




11





bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • When you first insert the row? Or whenever you update the row, too?

    – Rick James
    Apr 19 '17 at 1:24



















  • When you first insert the row? Or whenever you update the row, too?

    – Rick James
    Apr 19 '17 at 1:24

















When you first insert the row? Or whenever you update the row, too?

– Rick James
Apr 19 '17 at 1:24





When you first insert the row? Or whenever you update the row, too?

– Rick James
Apr 19 '17 at 1:24










1 Answer
1






active

oldest

votes


















0














You can create the pair of triggers ON INSERT and ON UPDATE that perform any desired transformations 'on the fly'



CREATE TRIGGER `myuuid_autoinserter` 
BEFORE INSERT ON `table` -- or BEFORE UPDATE
FOR EACH ROW
BEGIN
SET loooonguuid = CONCAT(OLD.uuid, OLD.uuid, OLD.uuid, OLD.uuid)
SET NEW.uuid = loooonguuid;
END


When you run some INSERT or UPDATE query on the table trigger will replace submitted value of the uuid by string stored in the loooonguuid variable.



Sure you can do as complex and randomized transformation as you want.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "182"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f171346%2fmysql-column-that-auto-generates-data-longer-than-uuid%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can create the pair of triggers ON INSERT and ON UPDATE that perform any desired transformations 'on the fly'



    CREATE TRIGGER `myuuid_autoinserter` 
    BEFORE INSERT ON `table` -- or BEFORE UPDATE
    FOR EACH ROW
    BEGIN
    SET loooonguuid = CONCAT(OLD.uuid, OLD.uuid, OLD.uuid, OLD.uuid)
    SET NEW.uuid = loooonguuid;
    END


    When you run some INSERT or UPDATE query on the table trigger will replace submitted value of the uuid by string stored in the loooonguuid variable.



    Sure you can do as complex and randomized transformation as you want.






    share|improve this answer




























      0














      You can create the pair of triggers ON INSERT and ON UPDATE that perform any desired transformations 'on the fly'



      CREATE TRIGGER `myuuid_autoinserter` 
      BEFORE INSERT ON `table` -- or BEFORE UPDATE
      FOR EACH ROW
      BEGIN
      SET loooonguuid = CONCAT(OLD.uuid, OLD.uuid, OLD.uuid, OLD.uuid)
      SET NEW.uuid = loooonguuid;
      END


      When you run some INSERT or UPDATE query on the table trigger will replace submitted value of the uuid by string stored in the loooonguuid variable.



      Sure you can do as complex and randomized transformation as you want.






      share|improve this answer


























        0












        0








        0







        You can create the pair of triggers ON INSERT and ON UPDATE that perform any desired transformations 'on the fly'



        CREATE TRIGGER `myuuid_autoinserter` 
        BEFORE INSERT ON `table` -- or BEFORE UPDATE
        FOR EACH ROW
        BEGIN
        SET loooonguuid = CONCAT(OLD.uuid, OLD.uuid, OLD.uuid, OLD.uuid)
        SET NEW.uuid = loooonguuid;
        END


        When you run some INSERT or UPDATE query on the table trigger will replace submitted value of the uuid by string stored in the loooonguuid variable.



        Sure you can do as complex and randomized transformation as you want.






        share|improve this answer













        You can create the pair of triggers ON INSERT and ON UPDATE that perform any desired transformations 'on the fly'



        CREATE TRIGGER `myuuid_autoinserter` 
        BEFORE INSERT ON `table` -- or BEFORE UPDATE
        FOR EACH ROW
        BEGIN
        SET loooonguuid = CONCAT(OLD.uuid, OLD.uuid, OLD.uuid, OLD.uuid)
        SET NEW.uuid = loooonguuid;
        END


        When you run some INSERT or UPDATE query on the table trigger will replace submitted value of the uuid by string stored in the loooonguuid variable.



        Sure you can do as complex and randomized transformation as you want.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 19 '17 at 10:48









        KondybasKondybas

        2,588912




        2,588912






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Database Administrators Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f171346%2fmysql-column-that-auto-generates-data-longer-than-uuid%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL Server 17 - Attemping to backup to remote NAS but Access is denied

            Always On Availability groups resolving state after failover - Remote harden of transaction...

            Restoring from pg_dump with foreign key constraints