2

If I specify a default when adding a non-null column to a table ...

ALTER TABLE foo
ADD COLUMN bar INT DEFAULT 42 NOT NULL

... does the bar column continue to have a default value? Or is the default only used while adding the column, to specify values in existing rows?

1 Answer 1

1

The documentation says:

The column-def rule defines the characteristics of the new column.

So the default value applies to the column, not to the operation:

sqlite> CREATE TABLE foo(x);
sqlite> ALTER TABLE foo ADD COLUMN bar INT DEFAULT 42 NOT NULL;
sqlite> INSERT INTO foo(x) VALUES(1);
sqlite> SELECT * FROM foo;
1|42
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.