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
I’m not sure if it’s the easiest way, but it works. The idea is to create a trigger that does all work for you, then, to execute a query that updates your table, and finally to drop this trigger:
Then execute
And
DROP TRIGGER beforeYourTableUpdate;UPDATE
Another solution that doesn’t use triggers, but requires primary key or unique index :
UPDATE once again:
It seems that your original query should also work (maybe you don’t need
WHERE columnID is not null, so all my fancy code is not needed.