SQLite Alter Table?

Not quite ALTER TABLE syntax, but it will work in a pinch. Hopefully they'll get ALTER TABLE into the 3.x release some time in the future. Until then here is syntax to do it now. Using transactions it's mostly safe and fairly quick. Probably a good idea to do a VACUUM after you're done.

BEGIN TRANSACTION;
CREATE TEMPORARY TABLE Bar(a,b);
INSERT INTO Bar SELECT a,b FROM Foo;
DROP TABLE Foo;
CREATE TABLE Foo(a,b);
INSERT INTO Foo SELECT a,b FROM Bar;
DROP TABLE Bar;
COMMIT;

Update: SQLite now support some limited ALTER TABLE commands.



Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
 
Logged IP: 34.229.63.28
To prevent spam please submit by clicking the kitten: