我们可以在android sqlite中使用截断查询

时间:2022-03-01 00:10:26

can we use truncate query in android database? otherwise can we performing truncate operation using our java code?

我们可以在android数据库中使用截断查询吗?否则我们可以使用我们的java代码执行截断操作吗?

3 个解决方案

#1


12  

If I have to truncate a table, I simply drop and recreate it.

如果我必须截断一个表,我只需删除并重新创建它。

Documentation ( http://www.sqlite.org/lang_delete.html ):

文档(http://www.sqlite.org/lang_delete.html):

When the WHERE is omitted from a DELETE statement and the table being deleted has no triggers, SQLite uses an optimization to erase the entire table content without having to visit each row of the table individually. This "truncate" optimization makes the delete run much faster.

#2


6  

DELETE FROM tablename
VACUUM

从表名VACUUM删除

Ex:

例如:

db.execSQL("DELETE FROM " + TABLE_NAME);
db.execSQL("VACUUM");

Note: this won't reset the row numbering for rows using AUTOINCREMENT. For that you'll need to drop the table and recreate it.

注意:这不会使用AUTOINCREMENT重置行的行编号。为此,您需要删除表并重新创建它。

source: http://phpcode.mypapit.net/how-to-truncate-table-in-sqlite-database/49/

来源:http://phpcode.mypapit.net/how-to-truncate-table-in-sqlite-database/49/

#3


1  

This is the code I used, just 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);

#1


12  

If I have to truncate a table, I simply drop and recreate it.

如果我必须截断一个表,我只需删除并重新创建它。

Documentation ( http://www.sqlite.org/lang_delete.html ):

文档(http://www.sqlite.org/lang_delete.html):

When the WHERE is omitted from a DELETE statement and the table being deleted has no triggers, SQLite uses an optimization to erase the entire table content without having to visit each row of the table individually. This "truncate" optimization makes the delete run much faster.

#2


6  

DELETE FROM tablename
VACUUM

从表名VACUUM删除

Ex:

例如:

db.execSQL("DELETE FROM " + TABLE_NAME);
db.execSQL("VACUUM");

Note: this won't reset the row numbering for rows using AUTOINCREMENT. For that you'll need to drop the table and recreate it.

注意:这不会使用AUTOINCREMENT重置行的行编号。为此,您需要删除表并重新创建它。

source: http://phpcode.mypapit.net/how-to-truncate-table-in-sqlite-database/49/

来源:http://phpcode.mypapit.net/how-to-truncate-table-in-sqlite-database/49/

#3


1  

This is the code I used, just 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);