python sqlite创建表语法

2024-10-04 07:26:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在数据库中创建一个新表。我以前在创建其他表时也这样做过,但这次我遇到了一个语法错误。据我所知,语法是正确的。所以我想不出来

下面是引发错误的语句的代码段:

cursor.execute('''
    CREATE TABLE IF NOT EXISTS order(
    orderID INTEGER PRIMARY KEY,
    productname STRING,
    productprice FLOAT,
    productquanitity INTEGER,
    producttotal INTEGER;''')

这是错误:

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

如果能就发生这种情况的原因提出一些建议,我将不胜感激


Tags: inpy数据库代码段错误line语法order
1条回答
网友
1楼 · 发布于 2024-10-04 07:26:05

order是SQL中的保留关键字;见documentation for the full list of reserved keywords that SQLite uses

使用"order"使SQLite理解它将被解释为表名。您还忘记了结束)

CREATE TABLE IF NOT EXISTS "order" (
    orderID INTEGER PRIMARY KEY,
    productname STRING,
    productprice FLOAT,
    productquanitity INTEGER,
    producttotal INTEGER
)

相关问题 更多 >