node ninja
node ninja

Reputation: 32986

How to do this in SQLite3?

Trying to do this in SQLite3.

ALTER TABLE foo MODIFY (vid NUMBER(6));

Upvotes: 1

Views: 49

Answers (1)

Larry Lustig
Larry Lustig

Reputation: 50970

You cannot modify a column in SQLite.

You must create a TEMPORARY table, drop the original, CREATE IT again, then INSERT back from the TEMPORARY table.

Assuming the number and order of the columns stays the same, and that your table contains no REFERENCEd PRIMARY or UNIQUE KEYs, you can use this simplified syntax:

CREATE TEMP TABLE TempTable AS SELECT * FROM YourTable;
DROP TABLE YourTable;
CREATE TABLE YourTable (col defs here. . .);
INSERT INTO YourTable SELECT * FROM TempTable;

If you're changing the number or order of columns, you'll have list the columns explicitly in the INSERT statement.

Upvotes: 2

Related Questions