Craig Tucker
Craig Tucker

Reputation: 1071

MySQL update md5 of another column

I need to do an update query making an md5 hash from my google calendar column. This is my query:

UPDATE `ea_appointments` SET `hash` = MD5(`id_google_calendar`)

Would this work to make something like this?:

Table: ea_appointments
id_google_calendar                             Hash
e5e3were760lkj792c7t5vm61bvk_20160729T200000Z  d5f9f4ef02e438d49c8bf39cd4b4118d

Upvotes: 2

Views: 2423

Answers (2)

MrGapo
MrGapo

Reputation: 348

I think it would work.

Also I suggest that you test it first. You can test query with:

  • Select statement: SELECT id_google_calendar, MD5(id_google_calendar) as hash FROM ea_appointments
  • Update record in test table. Create some test table add few record in it and run query

Upvotes: 0

cn0047
cn0047

Reputation: 17051

Yes, it'll be work. And you can loosely check it by:

select md5('test');

Result:

+----------------------------------+
| md5('test')                      |
+----------------------------------+
| 098f6bcd4621d373cade4e832627b4f6 |
+----------------------------------+

Or:

select md5('e5e3were760lkj792c7t5vm61bvk_20160729T200000Z');

Result:

+------------------------------------------------------+
| md5('e5e3were760lkj792c7t5vm61bvk_20160729T200000Z') |
+------------------------------------------------------+
| 06b5a13d9a7b0ed26ab1406434954972                     |
+------------------------------------------------------+

Or:

create table t(id_google_calendar varchar(100), hash varchar(100));
insert into t values ('e5e3were760lkj792c7t5vm61bvk_20160729T200000Z', '');
update t set Hash = md5(id_google_calendar);
select * from t;

Result:

+-----------------------------------------------+----------------------------------+
| id_google_calendar                            | hash                             |
+-----------------------------------------------+----------------------------------+
| e5e3were760lkj792c7t5vm61bvk_20160729T200000Z | 06b5a13d9a7b0ed26ab1406434954972 |
+-----------------------------------------------+----------------------------------+

Upvotes: 1

Related Questions