How do I change the default value of an existing column in a table in sqlite3?
I have a table named notes with a boolean column named hidden. The default is set to true, I want to set it to false.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
New Versions
SQLite now supports RENAME COLUMN, ADD COLUMN, and DROP COLUMN so you can change a column default by:
alter table t rename column c to c_oldalter table t add c boolean default falseupdate t set c = c_oldalter table t drop column c_oldThanks to dr fu manchu for a heads up on SQLite updating their ALTER TABLE support.
Older Versions
I don’t think you can without replacing the whole table. From the fine manual:
So there is no way to modify an existing column in SQLite. I think you’ll have to create a new table with the appropriate default for
hidden, copy all the data over, drop the originalnotestable, and then rename the new one.