如何在没有id的情况下删除数据库中的行

时间:2012-07-04 15:45:14

标签: android sqlite

我的应用程序中有一个无用的数据库。如何删除任何行?我的数据库代码如下:

mydb=Nickname.this.openOrCreateDatabase("private", 0, null);
            mydb.execSQL("CREATE TABLE IF NOT EXISTS numbers(nickname varchar,number INT(13))");

有人知道怎么可能吗?

mydb=Clear.this.openOrCreateDatabase("private", 0, null);
            mydb.execSQL("CREATE TABLE IF NOT EXISTS numbers(_id INTEGER PRIMARY KEY,nickname varchar,number INT(13))");
mydb.execSQL("DELETE FROM numbers WHERE id='=?' AND number='"+num+"'");

//num is string which contains which number i wish to delete

2 个答案:

答案 0 :(得分:1)

SQLDatabase对象有一个删除方法。 public int delete(String table,String whereClause,String [] whereArgs)

mydb.delete(TABLE, "nickname = "+ DatabaseUtils.sqlEscapeString(name), null);

答案 1 :(得分:0)

mydb.execSQL("DELETE FROM your_db.your_table WHERE  <write your SQL conditions here> ");