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.
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.
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.
If you want to delete a row by its rowid
, it is very straight forward, e.g.
delete from mytable where rowid=1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With