Set a Default Value for a Column in SQLite: DEFAULT Constraint

When creating a table in SQLite, you have the option of adding constraints to each column.

One such constraint is the DEFAULT constraint.

The DEFAULT constraint allows you to specify a value to be used in the event no value is supplied for that column when a new row is inserted.

If you don’t use a DEFAULT clause, then the default value for a column is NULL.

Read more

How iif() Works in SQLite

In SQLite, iif() is a conditional function that returns the second or third argument based on the evaluation of the first argument.

It’s logically equivalent to CASE WHEN X THEN Y ELSE Z END.

iif() is an abbreviation for Immediate IF.

The iif() function was introduced in SQLite 3.32.0, which was released on 22 May 2020.

Read more

Add a Generated Column to a Table in SQLite

You can add a generated column to an existing table in SQLite by using the ALTER TABLE statement.

SQLite’s implementation of the ALTER TABLE statement is very limited, but it does allow you to add a column – including generated columns.

Generated columns (also known as “computed columns”) are columns that get their value from an expression that computes values from other columns.

Read more