简体   繁体   中英

drop table in python with sqlite3

I have question about python and sqlite3. I want to drop a table from within Python. The command

cur.execute('drop table if exists tab1')

Does not work.

cur.executescript('drop table if exists tab1;')

does the job.

The execute method allows the creation of tables. However, it won't drop them? Is there a reason for this?

The cur.executescript command issues a COMMIT before running the provided script. Additionally a CREATE executes a COMMIT intrinsically. Perhaps you have an open transaction that needs committed before your changes take place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM