ameliabob 3 Report post Posted July 13, 2018 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
niche 129 Report post Posted July 13, 2018 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
Ingolme 938 Report post Posted July 13, 2018 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
justsomeguy 1,093 Report post Posted July 13, 2018 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
ameliabob 3 Report post Posted July 13, 2018 Actually I am executing this from within the sqlite "idle" shell Share this post Link to post Share on other sites
justsomeguy 1,093 Report post Posted July 13, 2018 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