iOS 里面创建SQL语句
NSString *sql_stmt;
sql_stmt = @"create table\
context_group\
(context_group_id int(5) not null auto_increment,\
context_group_title varchar(255) not null,\
context_group_father_id int(5),\
\
\
\
UNIQUE (context_group_id),\
PRIMARY KEY (context_group_id),\
FOREIGN KEY (context_group_father_id) REFERENCES context_group(context_group_id),\
)";
** 出现这个错误 **
Error inserting batch: near "auto_increment": syntax error
===
在SQLite里面 INTEGER 才支持自增。
所以需要修改
context_group_id int(5) not null auto_increment
改成
context_group_id INTEGER auto_increment
iOS 里面 建表语句
NSString *sql_stmt;
sql_stmt = @"create table\
email\
(email_id INTEGER PRIMARY KEY auto_increment,\
email VARCHAR(255) not null,\
UNIQUE(email_id))";
return sql_stmt;
这样是会报错的
NSString *sql_stmt;
sql_stmt = @"create table\
email\
(email_id INTEGER auto_increment,\
email_address VARCHAR(255) not null,\
UNIQUE(email_id),\
PRIMARY KEY (email_id)\
)";
这样才能正确执行
NSString *sql_stmt;
sql_stmt = @"create table\
tasks\
(tasks_id INTEGER not null auto_increment,\
tasks_title varchar(255) ,\
UNIQUE(tasks_id),\
PRIMARY KEY (tasks_id)\
)";
这里会报错
Error inserting batch: near "auto_increment": syntax error
===
not null 和 auto_increment 不能一起用
SQLite 里面没有枚举类型
但是你可以这样用:
CREATE TABLE Price (
PriceId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
Name VARCHAR(100) NOT NULL,
Type CHAR(1) NOT NULL DEFAULT ('M') REFERENCES PriceType(Type)
);
CREATE TABLE PriceType (
Type CHAR(1) PRIMARY KEY NOT NULL,
Seq INTEGER
);
INSERT INTO PriceType(Type, Seq) VALUES ('M',1);
INSERT INTO PriceType(Type, Seq) VALUES ('R',2);
INSERT INTO PriceType(Type, Seq) VALUES ('H',3);