본문 바로가기

BackEnd/Python-Flask

[백엔드] Flask: Python 으로 DB 삭제, delete

반응형

[ Delete ]

 

변수 1개를 활용하여 삭제


query = """Delete from Laptop where id = %s"""

# row to delete
laptopId = 6

cursor.execute(query,(laptopId,))
connection.commit()
print("Record Deleted successfully")

 

여러행삭제 - 리스트 안에 튜플

cursor = connection.cursor()

query = """Delete from Laptop where id = %s"""

records_to_delete = [(6,),(5,)]

cursor.executemany(query,records_to_delete)

connection.commit()

print("Record Deleted successfully")



반응형