Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UPDATE Query without WHERE Clause

I know it sounds to be a stupid question but I was wondering if the UPDATE query can be used without a WHERE clause. And if so in what conditions?

Thanks in advance.

like image 654
heretolearn Avatar asked Aug 28 '12 15:08

heretolearn


People also ask

Can we write an UPDATE query without WHERE clause?

The UPDATE statement in SQL is used to update records in the table. We can modify one or multiple records (rows) in a table using UPDATE statement. If you do not use WHERE clause in UPDATE statement, all the records in the table will be updated.

What happens when you UPDATE a table without a WHERE clause?

Without WHERE clauses, DELETE drops all the data from the table, and UPDATE overwrites values for all the table rows.

Can we use WHERE clause in UPDATE?

WHERE clause can be used with SQL UPDATE to add conditions while modifying records. Without using any WHERE clause, the SQL UPDATE command can change all the records for the specific columns of the table.

How do you UPDATE a table based on conditions?

Now what happens if you want to update rows in one table based on the condition of another table? This question leads to a few different ways you could do this. UPDATE table SET col = ( SELECT other_col FROM other_table WHERE other_table. table_id = table.id );


1 Answers

if you don't use the WHERE clause all the records on the table will be affected

like image 55
Massimiliano Peluso Avatar answered Oct 04 '22 01:10

Massimiliano Peluso