Vishnu
Vishnu

Reputation: 53

SQLite delete syntax error

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?

Upvotes: 2

Views: 3671

Answers (3)

gheese
gheese

Reputation: 1200

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

Upvotes: 0

Krzysztof Adamski
Krzysztof Adamski

Reputation: 2079

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.

Upvotes: 0

Alex Klimashevsky
Alex Klimashevsky

Reputation: 2495

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

Upvotes: 5

Related Questions