Reputation: 19
I am working on creating a new table within my database. I have done this before when creating other tables but this time I am facing a syntax error. As far as i can see, the syntax is correct. So, I cannot figure it out.
Below, there is a code snippet of the statement that is throwing the error:
cursor.execute('''
CREATE TABLE IF NOT EXISTS order(
orderID INTEGER PRIMARY KEY,
productname STRING,
productprice FLOAT,
productquanitity INTEGER,
producttotal INTEGER;''')
This is the error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "N:/NEW/cashregister.py", line 42, in okitem
producttotal INTEGER;''')
sqlite3.OperationalError: near "order": syntax error
I would be grateful for some suggestions on why this has occurred.
Upvotes: 0
Views: 161
Reputation: 1121794
order
is a reserved keyword in SQL; see the documentation for the full list of reserved keywords that SQLite uses.
Use "order"
to make SQLite understand that it is to be interpreted as a table name. You also forgot a closing )
:
CREATE TABLE IF NOT EXISTS "order" (
orderID INTEGER PRIMARY KEY,
productname STRING,
productprice FLOAT,
productquanitity INTEGER,
producttotal INTEGER
)
Upvotes: 2