SQL错误:接近“”threatAgent_id“”:语法错误[重复]

时间:2021-11-01 02:17:55

This question already has an answer here:

这个问题在这里已有答案:

i am trying to run the following query to make a table:

我试图运行以下查询来创建一个表:

CREATE TABLE "attack" (
      "id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL ,
      "name" VARCHAR , 
      "description" TEXT check(typeof("description") = 'text') , 
      "probability" DOUBLE ,

      "asset_id" INTEGER  ,
      FOREIGN KEY ( "asset_id") REFERENCES  asset(id)   ,

      "threatAgent_id" INTEGER  ,
      FOREIGN KEY ( "threatAgent_id") REFERENCES  threatAgent(id) ,

      "vulnerability_id"  INTEGER  ,
      FOREIGN KEY ( "vulnerability_id") REFERENCES  vulnerability(id)

 ) ;

but it complains that

但它抱怨说

 error: near ""threatAgent_id"": syntax error

i have made the threatAgent using the following query:

我使用以下查询创建了threatAgent:

CREATE TABLE "threatAgent" ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , "means" TEXT check(typeof("means") = 'text') , "motivation" VARCHAR, "capabilities" VARCHAR, "opportunities" VARCHAR)

So, why it is complaining?

那么,为什么抱怨呢?

1 个解决方案

#1


1  

It does not like interlacing column definitions with constraint definitions. So when it gets to the first constraint it thinks there won't be any more columns.

它不喜欢使用约束定义隔行列定义。因此,当它达到第一个约束时,它认为不再有任何列。

Move all the constraint definitions to the bottom to resolve.

将所有约束定义移到底部以解决。

CREATE TABLE "attack" (
      "id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL ,
      "name" VARCHAR , 
      "description" TEXT check(typeof("description") = 'text') , 
      "probability" DOUBLE ,
      "asset_id" INTEGER , 
      "threatAgent_id" INTEGER  ,
      "vulnerability_id"  INTEGER  ,

      FOREIGN KEY ( "asset_id") REFERENCES  asset(id)   ,
      FOREIGN KEY ( "threatAgent_id") REFERENCES  threatAgent(id) ,
      FOREIGN KEY ( "vulnerability_id") REFERENCES  vulnerability(id)

 ) ;

#1


1  

It does not like interlacing column definitions with constraint definitions. So when it gets to the first constraint it thinks there won't be any more columns.

它不喜欢使用约束定义隔行列定义。因此,当它达到第一个约束时,它认为不再有任何列。

Move all the constraint definitions to the bottom to resolve.

将所有约束定义移到底部以解决。

CREATE TABLE "attack" (
      "id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL ,
      "name" VARCHAR , 
      "description" TEXT check(typeof("description") = 'text') , 
      "probability" DOUBLE ,
      "asset_id" INTEGER , 
      "threatAgent_id" INTEGER  ,
      "vulnerability_id"  INTEGER  ,

      FOREIGN KEY ( "asset_id") REFERENCES  asset(id)   ,
      FOREIGN KEY ( "threatAgent_id") REFERENCES  threatAgent(id) ,
      FOREIGN KEY ( "vulnerability_id") REFERENCES  vulnerability(id)

 ) ;