0

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.

1 Answer 1

2

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
)
Sign up to request clarification or add additional context in comments.

2 Comments

There's also a missing closing paren, which will be the next syntax error to pop up.
dont worry have found it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.