baTimá
baTimá

Reputation: 544

How to delete ALL value from a Column in SQLite with a single click?

I want a button that deletes all the values inside a column with a single button click.

I know the code to delete the row or table but not all the values in it. Is it possible or do I have to delete the column and re-add it?

Upvotes: 1

Views: 2606

Answers (1)

Prizoff
Prizoff

Reputation: 4575

Something like this should be working:

ContentValues values = new ContentValues();
values.put(<COLUMN_NAME>, (String) null);
database.update(<TABLE_NAME>, values, null, null);

<COLUMN_NAME>, and <TABLE_NAME> are Strings, containing the column you want to clear and table name :)

Also, you can assign not only null value to <COLUMN_NAME>, but any other value you want. I.e.: 0, or "" (empty string), depending on your needs.

Upvotes: 5

Related Questions