"how to add default value in sqlite?" Code Answer

2

looks good to me. here are the docs.

sqlite> create table t1 (id integer primary key, name text, created date);
sqlite> .table
t1
sqlite> .dump
pragma foreign_keys=off;
begin transaction;
create table t1 (id integer primary key, name text, created date);
commit;

sqlite> alter table t1 add column status varchar default 'n';
sqlite> .dump
pragma foreign_keys=off;
begin transaction;
create table t1 (id integer primary key, name text, created date, status varchar default 'n');
commit;

sqlite> insert into t1 (name) values ("test");
sqlite> select * from t1;
1|test||n

dump your schema and verify that your table structure is there after calling alter table but before the insert. if it's in a transaction, make sure to commit the transaction before the insert.

$ sqlite3 test.db ".dump"
By mamills on April 27 2022

Answers related to “how to add default value in sqlite?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.