Neal
Neal

Reputation: 13

How to delete all comments from datasource in SQLite?

I know how to delete a comment by position, but how do you delete all comments from a datasource?

I want to delete it when a button is clicked.

Upvotes: 0

Views: 176

Answers (3)

PearsonArtPhoto
PearsonArtPhoto

Reputation: 39698

To delete all of the data in a table, you need to do something like this:

DELETE FROM table_name

Upvotes: 2

mvp
mvp

Reputation: 116167

Correct answer is

DELETE FROM mytable

Do NOT use * after DELETE - it will cause syntax error!

Using TRUNCATE mytable would have been tempting, but unfortunately SQLite does NOT support TRUNCATE.

However, SQLite does provide special optimization provision for DELETE FROM statement. Namely, if WHERE clause was not specified (like in our case), then all space taken by rows in table is reclaimed very quickly, so behaviour is similar to true TRUNCATE.

Upvotes: 1

Dawid Sajdak
Dawid Sajdak

Reputation: 3084

You should use TRUNCATE

TRUNCATE TABLE comments_table

Upvotes: 2

Related Questions