我试图在数据库中创建多个表

  • 本文关键字:创建 数据库 python sqlite
  • 更新时间 :
  • 英文 :

error:  cursor.execute(
sqlite3.OperationalError: near "Order": syntax error
import sqlite3
conn = sqlite3.connect("Cookie.DB")
print("The Employee database is created!")
cursor = conn.cursor()

cursor.execute(
"""
CREATE TABLE IF NOT EXISTS Customer(
customerID TXT PRIMARY KEY NOT NULL,
customerFirstName TEXT NOT NULL,
customerLastName TXT NOT NULL,
address TXT NOT NULL,
email TXT NOT NULL,
Phone TXT NOT NULL,
creditCardInfo TXT NOT NULL

)
CREATE TABLE IF NOT EXISTS Order(
orderID TXT PRIMARY KEY NOT NULL,
FOREIGN KEY (customerID)
REFERENCES Customer (customerID),
customerName TXT NOT NULL,
FOREIGN KEY (cartID)
REFERENCES ShoppingCart (cartID),
orderPrice float NOT NULL,
dateCreated date NOT NULL,
dateShipped date NOT NULL
)
CREATE TABLE IF NOT EXISTS Cookies(
CookieID TXT PRIMARY KEY NOT NULL,
cookieName TXT NOT NULL,
unitCost float NOT NULL,
soldOutOrNot bool NOT NULL

)

CREATE TABLE IF NOT EXISTS ShoppingCart(
CartID TXT PRIMARY KEY NOT NULL,
FOREIGN KEY (customerID)
REFERENCES Customer (customerID),
FOREIGN KEY (cookieID)
REFERENCES Cookies (cookieID),
quantity INT NOT NULL,
dateAdded date NOT NULL,
soldOutOrNot bool NOT NULL
)
"""
)
conn.commit()
print("The employee table is created!")

我看到你使用的语法是错误的,就我所能理解的尝试运行单个查询,如

import sqlite3
conn = sqlite3.connect("mydatabase.db") 
cursor = conn.cursor()
# run for each table...
cursor.execute("""CREATE TABLE albums
(title text, artist text, release_date text, 
publisher text, media_type text)""")

相关内容

  • 没有找到相关文章

最新更新