O que é CRUD + DELETE com e sem WHERE no SQLite3 do Python

This commit is contained in:
Luiz Otávio
2023-04-02 08:48:32 -03:00
parent f8eb69afad
commit b0f78cff48

View File

@@ -9,10 +9,15 @@ TABLE_NAME = 'customers'
connection = sqlite3.connect(DB_FILE)
cursor = connection.cursor()
# CRUD - Create Read Update Delete
# SQL - INSERT SELECT UPDATE DELETE
# CUIDADO: fazendo delete sem where
cursor.execute(
f'DELETE FROM {TABLE_NAME}'
)
# DELETE mais cuidadoso
cursor.execute(
f'DELETE FROM sqlite_sequence WHERE name="{TABLE_NAME}"'
)
@@ -51,7 +56,6 @@ cursor.executemany(sql, (
{'nome': 'Joana', 'peso': 5},
))
connection.commit()
cursor.close()
connection.close()