[Python] How to clean the database, dropping all records using sqlalchemy?

Discussão em 'Python' iniciado por Stack, Setembro 4, 2025.

  1. Stack

    Stack Membro Participativo

    I am using SQLAlchemy. I want to delete all the records efficiently present in database but I don't want to drop the table/database.

    I tried with the following code:

    con = engine.connect()
    trans = con.begin()

    con.execute(table.delete())
    trans.commit()


    It seems, it is not a very efficient one since I am iterating over all tables present in the database. Can someone suggest a better and more efficient way of doing this?

    Continue reading...

Compartilhe esta Página