mysql add tag
In MySQL, to update a table in the default safe mode, one needs to update by use of a `WHERE` and a `KEY`.

How does one update a whole table?

I've used the following

update string_tbl
set char_fld="HI",vchar_fld="Thiis is ok!"
where pk_fld;

where `pk_fld` is the `PRIMARY KEY` of `string_tbl`.

Is this a proper way to do it? Or may I encounter some problems in the near future?
Top Answer
Jack Douglas
Yes that is the 'proper' way to do it, or (better) simply turn off safe mode temporarily:

update string_tbl set char_fld="HI",vchar_fld="Thiis is ok!";

From [the manual](

> Enabling `sql_safe_updates` causes `UPDATE` and `DELETE` statements to produce an error if they do not specify a key constraint in the WHERE clause, or provide a LIMIT clause, or both.

But also:

> For beginners, a useful startup option is `--safe-updates` (or `--i-am-a-dummy`, which has the same effect). Safe-updates mode is helpful for cases when you might have issued an `UPDATE` or `DELETE` statement but forgotten the `WHERE` clause indicating which rows to modify.

Perhaps it would be better to disable safe mode entirely and live with the discipline of not forgetting your `where` clauses — that's hardly the only foot-gun you could shoot yourself with anyway!

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.