delete all record from table in mysql

Mysql

Mysql Problem Overview


I am trying to delete all records from a table. My query is:

delete from tableName.

But it reports the following error:

> Error Code: 1175. You are using safe update mode and you tried to > update a table without a WHERE that uses a KEY column To disable safe > mode, toggle the option in Preferences -> SQL Editor -> Query Editor > and reconnect."

How do I resolve this?

Mysql Solutions


Solution 1 - Mysql

truncate tableName

That is what you are looking for.

Truncate will delete all records in the table, emptying it.

Solution 2 - Mysql

It’s because you tried to update a table without a WHERE that uses a KEY column.

The quick fix is to add SET SQL_SAFE_UPDATES=0; before your query :

SET SQL_SAFE_UPDATES=0; 

Or

close the safe update mode. Edit -> Preferences -> SQL Editor -> SQL Editor remove Forbid UPDATE and DELETE statements without a WHERE clause (safe updates) .

BTW you can use TRUNCATE TABLE tablename; to delete all the records .

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSamiView Question on Stackoverflow
Solution 1 - MysqlThirlerView Answer on Stackoverflow
Solution 2 - MysqlSandeep PathakView Answer on Stackoverflow