David Garcia
David Garcia

Reputation: 2696

SQL: UPDATE Without WHERE Clause

Would updating 1 million records without specifying the WHERE clause be quicker than specifying it?

UPDATE test
SET col1 = 'somevalue';

UPDATE test
SET col1 = 'somevalue'
WHERE col2 > 0;

Apologies for the noob question, logically I think is quicker without specifying it as it would not check where the condition meets, however, it could also mean that it will skip updating a row where the condition doesn't meet.

Is there an online tool that I can test speed with sample data.

Thanks for helping.

Upvotes: 0

Views: 1960

Answers (1)

Jason W
Jason W

Reputation: 13179

The answer is that it depends. If only 10 out of the 1 million records met the condition and the condition has a solid index, then that is much faster than updating everything.

Upvotes: 1

Related Questions