SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Evangelist artcoder's Avatar
    Join Date
    Aug 2005
    Location
    Planet Earth
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generate random string

    I'm writing a sequence of insert statements which I want to execute via the phpmyadmin interface to insert records into a table.

    The table contains only two columns: name and uid. The first column is obvious. The second column is just a random string of 32 characters.

    My insert statement are of the form ...

    INSERT INTO user_table (name, uid) VALUES('Some Body', '3433dfdfkdsfjdfddf33dfkdfk');
    INSERT INTO user_table (name, uid) VALUES('Another Body', 'ewrkdk32832wrekldfnejdsfdsf');

    I want to know if there is an easier way write the insert statement so that the statement will generate the random 32 character string for me.

    Such as something of the form....

    INSERT INTO user_table (name, uid) VALUES('Some Body', RANDOM(32));

    Or is there a way to tell phpmyadmin to populate the "uid" column of existing records with a random string if that column contains NULL.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    try the UUID() function
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Obey the Purebreed trib4lmaniac's Avatar
    Join Date
    Dec 2004
    Location
    Cornwall, UK
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    try the UUID() function
    You could combine this with MD5() to get 32 characters.
    Code SQL:
    INSERT INTO user_table (name, uid) VALUES('Some Body', MD5(UUID()));

  4. #4
    SitePoint Evangelist artcoder's Avatar
    Join Date
    Aug 2005
    Location
    Planet Earth
    Posts
    599
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the super quick responses.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •