are we able to use truncate query in android database? otherwise are we able to carrying out truncate operation using our java code?
If I must truncate a table, I merely drop and recreate it.
Documentation ( http://www.sqlite.org/lang_delete.html ):
Once the Where's overlooked from the Remove statement and also the table being erased doesn't have triggers, SQLite uses an optimisation to erase the whole table content without needing to visit each row on the table individually. This "truncate" optimisation helps make the remove run considerably faster.
This is actually the code I made use of, only for illustration:
private static final String TABLE_SCHEMA = "CREATE TABLE " + TABLE_NAME + " (\"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , \"runtime\" INTEGER, \"timestamp\" DATETIME DEFAULT CURRENT_TIMESTAMP)"; db.execSQL("DROP TABLE " + TABLE_NAME); db.execSQL(TABLE_SCHEMA);
Remove FROM tablename
db.execSQL("DELETE FROM " + TABLE_NAME); db.execSQL("VACUUM");
Note: this will not totally reset the row numbering for rows using AUTOINCREMENT. For your you will need to drop the table and recreate it.