Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete a row in first position the sqlite in android

Tags:

android

sqlite

How to delete a row in first position the sqlite in android Now i am using this code for delete the row

public void delete(String id)
{
    SQLiteDatabase db = this.getReadableDatabase();
    db.delete(TABLE_CONTACTS, KEY_ID + "=?", new String[]{id});
   // db.execSQL(TABLE_CONTACTS , " ORDER BY " + KEY_ID + " ASC;");
    db.close();
}

But i want to delete the row in first position. Because KEY_ID will not be the same all the time when deletion occur

like image 723
Nithinlal Avatar asked Mar 13 '13 04:03

Nithinlal


People also ask

How do I delete a row in SQLite?

In order to delete a particular row from a table in SQL, we use the DELETE query, The DELETE Statement in SQL is used to delete existing records from a table. We can delete a single record or multiple records depending on the condition we specify in the WHERE clause.

How do I remove something from a table in SQLite?

The TRUNCATE TABLE statement is used to remove all records from a table. SQLite does not have an explicit TRUNCATE TABLE command like other databases. Instead, it has added a TRUNCATE optimizer to the DELETE statement. To truncate a table in SQLite, you just need to execute a DELETE statement without a WHERE clause.

How do I delete multiple records in SQLite?

If you wanted to delete a number of rows within a range, you can use the AND operator with the BETWEEN operator. DELETE FROM table_name WHERE column_name BETWEEN value 1 AND value 2; Another way to delete multiple rows is to use the IN operator.


1 Answers

use this method to delete first row

    public void deleteFirstRow()
{
    db.open();
    Cursor cursor = db.query(TABLE_CONTACTS, null, null, null, null, null, null); 

        if(cursor.moveToFirst()) {
            String rowId = cursor.getString(cursor.getColumnIndex(KEY_ID)); 

            db.delete(TABLE_CONTACTS, KEY_ID + "=?",  new String[]{rowId});
           }
db.close();
    }   
like image 177
AwadKab Avatar answered Sep 24 '22 14:09

AwadKab