What happens when you execute an UPDATE statement without a WHERE clause?

A MySQL command- line client is started with safe updates disabled.
Mysql – -safe – updates=0
What happens when you execute an UPDATE statement without a WHERE clause?

A MySQL command- line client is started with safe updates disabled.
Mysql – -safe – updates=0
What happens when you execute an UPDATE statement without a WHERE clause?

A.
Results in an error

B.
Updates every row in the specified table(s)

C.
Results in – -safe-updates being enabled automatically

D.
Causes a syntax error

Explanation:
Reference:
http://justalittlebrain.wordpress.com/2010/09/15/you-are-using-safe-update-mode-and-youtried-to-update-a-table-without-a-where-that-uses-a-key-column/



Leave a Reply 9

Your email address will not be published. Required fields are marked *


Auriemma Francesco

Auriemma Francesco

correct is A

swdx

swdx

Correct is B. A would be correct if you had safe updates enabled.

Jay

Jay

B

SET sql_safe_updates=0;

CREATE TABLE t1 (i INT, j INT);
INSERT INTO t1 VALUES(1,1),(2,3);

update t1 set i = 3;

SELECT * FROM t1;

i, j
‘3’, ‘1’
‘3’, ‘3’

Ray

Ray

B is correct.

123

123

sql_safe_updates or –safe-updates(when you start the client) option prevents row modifications, such as update or delete that do not specify the KEY values.
DELETE FROM tb WHERE key = 1; will be deleted
DELETE FROM tb WHERE col = 1; will not be deleted if the col does not have key

123

123

when you set sql_safe_updates to true/1