我需要进行一个涉及用户创建的表的主键的查询:
CREATE TABLE Users (
ID PRIMARY KEY,
email VARCHAR(32) NOT NULL,
password VARCHAR(32) NOT NULL,
token VARCHAR(32),
firstname VARCHAR(32) NOT NULL,
lastname VARCHAR(32) NOT NULL,
gender VARCHAR(32) NOT NULL,
city VARCHAR(32) NOT NULL,
country VARCHAR(32) NOT NULL
);
问题是条目在表格中没有先前的ID条目:
sqlite> select * from Users;
|test1@test1.com|pbkdf2:sha1:1000$1QH0MnIO$379005819d14d578684a54ccbed92716187b6
aed||test1|test1|male|test1|test1
|aaa@aaa.com|pbkdf2:sha1:1000$LhxdRneM$62e02ab5f50715a3f52ae018bc49178c6b31b31b|
97IEx8M9aHC8lmaU0IQtsgxd4lMLPYGm|aaa|aaa|male|aaa|aaa
|bbb@bbb.com|pbkdf2:sha1:1000$BqGePRKD$7252a3b9342f50375cd75be7c70280ea211662b5|
BPVo7nxOe1mx35jdMnaH6GY74JC1Tzh3|bbb|bbb|male|bbb|bbb
|ccc@ccc.com|pbkdf2:sha1:1000$IU7zEn6C$9511fe277e8ce1822b4de4823dac4402fad1b652|
fmfyrWSec8BmUAFhgiQF5mFhhN8jqXDw|ccc|ccc|male|ccc|ccc
根据this问题,必须使用主整数键创建表:
CREATE TABLE Users (
ID INTEGER PRIMARY KEY,
email VARCHAR(32) NOT NULL,
password VARCHAR(32) NOT NULL,
token VARCHAR(32),
firstname VARCHAR(32) NOT NULL,
lastname VARCHAR(32) NOT NULL,
gender VARCHAR(32) NOT NULL,
city VARCHAR(32) NOT NULL,
country VARCHAR(32) NOT NULL
);
是否可以在不重新创建表的情况下修改主键?