2

This line, mDatabase.execSQL(sql);, gives me the following error:

{ sqlite returned: error code = 1, msg = near "*": syntax error }
  for Delete * from table_name Query

My SQL query is : DELETE * FROM table_name

How can I solve this?

2
  • can u put your log cat here.. Commented Aug 10, 2012 at 11:15
  • i am unable to attach the log cat now, but I need to tell you one thing, That statement mDatabase.execSQL(sql); is working fine for the query like: DELETE FROM table_name WHERE key=2 . But for this DELETE * FROM table_name only this is not working. i am using sql cipher library (jar) for the Database operations. thanks in advance. Commented Aug 10, 2012 at 12:00

3 Answers 3

5

DELETE * FROM table_name is a wrong sql command. Use DELETE from table_name

Sign up to request clarification or add additional context in comments.

4 Comments

For a simple reason- you can only delete the row, not a certain set of columns which * denotes.
I need to delete complete table, As per your query we can delete only one row that to we need to use WHERE clause with some primary key value.
use this query without where and you delete all rows from table
ok thanks, let me try this and i need to change one thing that my query is correct only right, because i need to support both queries (if both are correct) [link] (w3schools.com/sql/sql_delete.asp) to delete all rows.
0

Syntax error means that basically your statement is spelled wrong and it can not be parsed. In this case error message states where exactly this error occurred - on "*" character. In such case you should go to database documentation and check proper syntax of the command you are trying to use. In case of SQLite it's here. You can find documentation about DELETE statement there, here is the link. It shows you the syntax in graphical way (called syntax diagrams or railroad diagrams) which should be quite easy to follow. In this case, as mentioned earlier, you just can't specify "*" between DELETE and FROM. This is because you are always deleting whole rows and you can't delete individual selected columns.

5 Comments

thanks, i understand something but right now i am using sql cipher library (jar) for the database operations. Is there any way to find wheather this sqlcipher.jar will support this type of query.?
If I understand this correctly, sqlchipher should not influence sql queries in any way and it should support the same queries (and the same syntax) as normal SQLite.
ok, Thanks for your reply, then why i am getting this error particularity for this query only. It is working fine for the DELETE FROM table_name WHERE key=3, it is giving the error for DELETE * FROM only. I am using same mDatabase.exceSQL(sql) same statement to execute all the Queries. Any other way to solve this.
You should use DELETE FROM table_name, you can't use '*' inside the query. You are just using wrong syntax. If you want to delete all the rows you use DELETE FROM table_name without any WHERE clause and that's all.
thanks. I will do this implementation and get back to you if it works. Thank you so much for your time.
0

If you need to delete the entire table can you use DROP TABLE IF EXISTS then recreate the table

1 Comment

Thanks. As per the Krzysztof Adamski words i solved this. Thank you very much for your valuable Time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.