注册 登录
编程论坛 SQLite论坛

sqlite 查询报语法错误,求大神分析

leichencsu 发布于 2016-01-22 17:01, 7205 次点击

创建一张表,
CREATE TABLE [realcircs]
([index] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
[curr_date] string DEFAULT CURRENT_DATE NOT NULL,
[curr_time] string DEFAULT CURRENT_TIME NOT NULL,
[content] string DEFAULT '未填' NULL,[status] BOOLEAN DEFAULT 'false' NOT NULL)

然后写了个很简单的查询语句:
select * from realcircs where index = 1;
但是执行却是失败的:
SQL Error: near "index": syntax error  <select * from realcircs where index = 1;>
感觉也是符合sql语法的,不知为啥失败,求指导
2 回复
#2
不懂才问2016-01-25 20:08
sqlite> create table realcircs(
   ...> index integer not null primary key autoincrement,
   ...> curr_date string default current_date not null,
   ...> curr_time string default current_time not null,
   ...> content string default '未填' null,
   ...> status boolean default 'false' not null);
Error: near "index": syntax error
sqlite>

按着你的语法建立表  就提示错啦!

#3
不懂才问2016-01-25 20:46
关键问题   应该是index  应该是sqlite的命令关键字   不能当作表字段名

下面的语法   可以建立你要的表  

sqlite> create table realcircs3(
   ...> id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
   ...> curr_date char(15) default current_date not null,
   ...> content char(50) default '未填' not null,
   ...> status boolean default 'false' not null);
sqlite>

然后,这样就可以查询了
sqlite> select * from realcircs3 where id=1;
1|2016年1月25日|不知道填啥|true



1