Jump to content

Dropping a table


ameliabob

Recommended Posts

In all the examples they all seem to create a table before accessing it. How would I go about accessing one that has already been created the following code

	import sqlite3
	conn = sqlite3.connect('earnings.db')
cur = conn.cursor()
DROP TABLE closed
cur.execute('CREATE TABLE closed (rowId INTEGER PRIMARY KEY AUTOINCREMENT, nature TEXT)
	

This generates a Syntax Error with TABLE highlighted in Red.

If I remove the DROP line then I get the error that the table already exists

?????

Link to comment
Share on other sites

Do a 'SELECT * FROM closed' .  If no error, it's still there unless corrupted.

closed is not a reserved word, but close is.

 

Link to comment
Share on other sites

You can't just mix SQL and Python, you have to put the SQL in a string and pass the string into a database method.

Try passing the "DROP TABLE" line as a string into the execute() method. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...