【问题标题】:I have a query which contains mistakes. where are they?我有一个包含错误的查询。他们在哪?
【发布时间】:2021-01-19 00:01:06
【问题描述】:

我想在 SQlite 中创建一个表但不能:

CREATE TABLE IF NOT EXISTS[Goods] 
                    (GoodId INTEGER PRIMARY KEY AUTOINCREMENT,  
                    GoodName varchar(100) not null,
                    CategoryId INTEGER FOREIGN KEY (CategoryId) REFERENCES Category (CategoryId),  
                    ProducerId INTEGER FOREIGN KEY (ProducerId) REFERENCES Producer (ProducerId),
                    Price REAL not null, 
                    GoodCount REAL not null)

这里还有一些表格,但它们都可以。我对他们没有问题:

CREATE TABLE IF NOT EXISTS[Category] (CategoryId INTEGER PRIMARY KEY
                    AUTOINCREMENT, CategoryName varchar(100) not null)

CREATE TABLE IF NOT EXISTS[Producer] (ProducerId INTEGER PRIMARY KEY
                    AUTOINCREMENT, ProducerName varchar(100) not null)

【问题讨论】:

  • 你得到什么错误?发布表的定义:Category 和 Producer。
  • 您遇到了哪个错误?请edit your question添加此重要信息。

标签: sql sqlite foreign-keys create-table system.data.sqlite


【解决方案1】:

内联外键不采用FOREIGN KEY 关键字。

考虑:

CREATE TABLE IF NOT EXISTS[Goods] (
    GoodId INTEGER PRIMARY KEY AUTOINCREMENT,  
    GoodName varchar(100) not null,
    CategoryId INTEGER REFERENCES Category (CategoryId),  
    ProducerId INTEGER REFERENCES Producer (ProducerId),
    Price REAL not null, 
    GoodCount REAL not null
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-05
    • 2016-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多