Generate GUID in MySQL for existing Data?

Tom picture Tom · Jun 8, 2011 · Viewed 181.9k times · Source

I've just imported a bunch of data to a MySQL table and I have a column "GUID" that I want to basically fill down all existing rows with new and unique random GUID's.

How do I do this in MySQL ?

I tried

UPDATE db.tablename
  SET columnID = UUID()
  where columnID is not null

And just get every field the same

Answer

Rakesh Prajapati picture Rakesh Prajapati · Jul 9, 2012

I had a need to add a guid primary key column in an existing table and populate it with unique GUID's and this update query with inner select worked for me:

UPDATE sri_issued_quiz SET quiz_id=(SELECT uuid());

So simple :-)