【问题标题】:Sqlite does not accept create tableSqlite 不接受创建表
【发布时间】:2020-08-28 10:21:28
【问题描述】:

我正在尝试在终端的 sqlite3 上创建一个表。该命令如下所示:

CREATE TABLE test (
id int not null auto_increment primary key ,
col2 varchar(25) not null ,
col2 varchar(40) not null ,
col3 varchar(20) not null ,
col4 float not null
) engine = MYISAM ;

我经常收到Error: near "auto_incement": syntax error,但我找不到。任何修复它的建议都会非常有帮助。 感谢您的宝贵时间。

【问题讨论】:

    标签: sql sqlite auto-increment


    【解决方案1】:

    您的语法错误。
    关键字应为AUTOINCREMENT 而不是AUTO_INCREMENT,并且只能在将列定义为INTEGER PRIMARY KEY 时使用。
    但话又说回来,你并不真的需要 AUTOINCREMENT 在定义中:

    id INTEGER PRIMARY KEY
    

    通过将列定义为integer primary key,它也将自动递增。
    如果在定义中使用关键字AUTOINCREMENT

    id INTEGER PRIMARY KEY AUTOINCREMENT
    

    那么id 列中的值将永远不会被重用(因此在删除一行后,id 中会出现空白)。
    当然不需要NOT NULL,因为你定义了一个主键并且SQLite不支持存储引擎的定义(就像MySql那样)。
    所以把你的陈述改成这样:

    CREATE TABLE test (
      id integer primary key ,
      col1 varchar(25) not null ,
      col2 varchar(40) not null ,
      col3 varchar(20) not null ,
      col4 float not null
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      • 2018-12-30
      • 1970-01-01
      • 2017-02-25
      相关资源
      最近更新 更多