Delete Data from Table in SQLite3 Database in Python
Delete Data in SQLite3 Database Table
- If you want to delete data then you can delete only one at a time.
- Anyhow if you want to delete the whole data then we can go with loop to delete all data one by one.
Query to Delete data in database
"delete from table_name where searchable_column_name=?",(searchable_column_name data_,)
- Here column_name is the name of the column,which you want to delete.
- Searchable_column_name is nothing but the location of the row which you want to delete example the primary key value.
- The data matched with searchable_column_value_data, there we have to delete the mentioned column_name.
Below is the data what we have in our database with table_name as Employee_Data and Id, Name and Salary as column name
Now let's delete Data for Id 103
# program
import sqlite3 as sql
conn = sql.connect("Employee_Details.db")
curs = conn.cursor()
curs.execute("delete from Employee_Data where Id=?",(103,))
print("Data deleted successfully ")
conn.commit()
conn.close()
#Output
Data deleted successfully
so in above query, we tried to delete the full data for Id 103
New Data in database
If you forget to commit(), data will not reflect in Database, as it will not get saved.
Comments
Post a Comment