Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete query not working in mysql

Tags:

sql

mysql

I am trying to delete all records from a table called user_enrole.I am using this query

DELETE * FROM user_enrole

I think syntax of my query is not wrong but it is giving me error saying

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM user_enrole' at line 1

I have doubled check my syntax i am not able to figure out what is going wrong can someone point out please.

Is it occuring because of the relationship this table has with use table or what?

like image 709
user3570249 Avatar asked Apr 26 '14 18:04

user3570249


People also ask

Why delete query is not working in MySQL?

Solution. By default, MySQL workbench is started in safe mode, and can't update or delete, without a “WHERE” condition, see the error message. To fix it, in menu, selects “Edit” -> “Preferences” -> “SQL Queries”, uncheck the “Safe Updates” checkbox. Done, try reconnect and issue the delete command again.

Is deletion possible in MySQL?

You can specify multiple tables in a DELETE statement to delete rows from one or more tables depending on the condition in the WHERE clause. You cannot use ORDER BY or LIMIT in a multiple-table DELETE .


1 Answers

You don't need to use the asterisk in a delete. Just do DELETE FROM user_enrole to delete all records.

If you want to delete specific records filtered by one or more conditions, you will specify those conditions in the WHERE clause, like so:

DELETE FROM user_enrole
WHERE somecolumn > 1
AND anothercolumn = 'Username'
like image 158
shree.pat18 Avatar answered Sep 30 '22 14:09

shree.pat18