它不要求您使用 Int64,但是,它可能仅在您指定数字主键时才允许。因为 sqlite 并没有真正的引用完整性检查(尽管最近对此进行了讨论,也许 hipp 博士甚至已经实现了,但我最近没有检查过),所有主键意味着“使该列唯一并在它”。它没有什么特别之处。您当然可以使用 varchar 或 text 作为主键。例如,这有效:
create table t_test (
theID varchar(36) primary key,
nm varchar(50)
)
在上面,您可以使用 ID 以文本形式存储 guid。
更多信息可以在这里找到:http://www.sqlite.org/lang_createtable.html#rowid
@weenet ... per your comments, the following code works just fine.
如果您仍然遇到问题,我认为您需要发布您的代码。
create table t_test2 (
theID int32 primary key,
nm varchar(50)
);
insert into t_test2 (theID, nm) values (1, 'don');
insert into t_test2 (theID, nm) values (2, 'weenet');
select * from t_test2;
此外,这段代码运行良好(varchar 作为主键):
create table t_test (
theID varchar(36) primary key,
nm varchar(50)
)
insert into t_test (theID, nm) values ('abcdefg', 'don');
insert into t_test (theID, nm) values ('hijklmnop', 'weenet');
select * from t_test