jeudi 15 octobre 2015

Updating id primary key in sqlite3

I need to make a query that involves the primary key of a table Users created as:

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
);

The problem is that the entries have no preceding ID entry within the table:

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

According to this question the table must be created using a primary integer key:

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

);

Would it be possible to modify the primary key without recreating the table?

Aucun commentaire:

Enregistrer un commentaire