Jump to content
Sign in to follow this  
ameliabob

Dropping a table

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

?????

Share this post


Link to post
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.

 

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

That's a syntax error because you wrote the SQL code in the middle of your python code.

Share this post


Link to post
Share on other sites

And inside the SQLite shell, you need to import the sqlite3 package?  I'm pretty sure you showed python code there.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...