Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQlite3 - Delete row by rowid

Tags:

python

sql

sqlite

I'm currently building a small web app with Flask and I'm using SQLite3 as database. I want to implement a feature to delete rows in the database. To do that I have to select/delete the row by the standard rowid that SQLite3 is giving every row, but I don't know how to do that.

I know you can get the rowid of a row by:

SELECT rowid, * FROM table;

but I don't know how to reverse that.

like image 759
lennahht Avatar asked Sep 22 '17 17:09

lennahht


People also ask

Does RowID change in SQLite?

A rowid is assigned to a row upon insert and is imutable (never changing) unless the row is deleted and re-inserted (meaning it is another row, not the same row!) However, rows can be deleted+inserted by various commands "transparently", IF the DBA/table owner has set the "enable row movement" clause on the table.

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

If you want to delete a row by its rowid, it is very straight forward, e.g.

  delete from mytable where rowid=1;
like image 72
nos Avatar answered Oct 06 '22 13:10

nos