可以用 SQL 的 DELETE 子句删除表中的记录。例如:
import sqlite3
db_filename = 'company.db'
with sqlite3.connect(db_filename) as conn:
cursor = conn.cursor()
cursor.execute("""
DELETE from Employee
where id = 3
""")
conn.commit()
cursor.execute("""
select id, name, date, salary from Employee
order by date
""")
print('\nNext 5 employees:')
for row in cursor.fetchmany(5):
Employee_id, name, date, salary = row
print('{:2d} {:<25} ({}) [{:<8}]'.format(Employee_id, name, date, salary))
输出:
Next 5 employees:
2 Zhang ping (2008-01-05) [7000.5 ]
1 Wang wei (2016-01-02) [8000.5 ]
|