How to Limit a SQLite Column to a List of Values with CHECK and IN
A status, a priority or a size usually comes from a short, fixed list. SQLite has no enum type, but a CHECK with IN does the same job: the column accepts only the values you list. This guide limits a ticket's priority to low, medium and high, with real output from SQLite 3.54.1.
Syntax
<column> <type> CHECK (<column> IN (<value 1>, <value 2>, <value 3>))
| Part | What it means |
|---|---|
<column> IN (...) | True when the column's value is one of the values in the list |
<value 1>, <value 2>, ... | The allowed values, separated by commas. Text goes in single quotes |
CHECK (...) | Refuses any row for which the IN is false |
SQLite's documentation on IN: "The IN and NOT IN operators take an expression on the left and a list of values or a subquery on the right."
Prerequisites
- The sqlite3 command-line shell. This guide uses SQLite 3.54.1. Run
sqlite3 --versionto see yours; the SQLite download page has the command-line tools for Windows, macOS and Linux.
Step 1: Write the Script
Save this as in_list.sql:
CREATE TABLE tickets (
title TEXT NOT NULL,
priority TEXT NOT NULL CHECK (priority IN ('low', 'medium', 'high'))
);
INSERT INTO tickets (title, priority) VALUES ('Printer jam', 'low');
INSERT INTO tickets (title, priority) VALUES ('Server down', 'high');
INSERT INTO tickets (title, priority) VALUES ('Coffee machine', 'urgent');
SELECT * FROM tickets;

priority IN ('low', 'medium', 'high')lists the three allowed priorities.CHECK (...)turns that list into a rule for every row.- The first two tickets use allowed values. The third uses
'urgent', which isn't on the list.
Step 2: Run It
In the folder that holds the script, run:
sqlite3 -table helpdesk.db ".read in_list.sql"
sqlite3 opens the database file helpdesk.db, and creates it when it isn't there. -table prints each result as a table, and .read runs the statements in the script. The command is the same in bash, zsh and PowerShell.
Error near line 8 of in_list.sql: CHECK constraint failed: priority IN ('low', 'medium', 'high')
+-------------+----------+
| title | priority |
+-------------+----------+
| Printer jam | low |
| Server down | high |
+-------------+----------+

low and high are on the list, so those tickets went in. urgent isn't, so SQLite refused the coffee machine ticket and quoted the rule in the error.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Using a different case, 'High' | Refused with the same error: 'High' isn't 'high', because text comparison is case-sensitive | Use the exact values from the list |
A CHECK with IN on a column that allows NULL | A ticket with no priority went in: NULL IN (...) isn't false, so it passes | Add NOT NULL when the value is required |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
CHECK constraint failed: priority IN ('low', 'medium', 'high') | The value isn't on the list, or differs in case | Use one of the listed values |
Parse error near line 1 of in_list.sql: table tickets already exists | The script already ran on helpdesk.db | Delete helpdesk.db and run the script again |
FAQ
Can I use IN outside a CHECK?
Yes, anywhere a condition goes. SELECT title FROM tickets WHERE priority IN ('medium', 'high'); returned Server down.
How do I say "not one of these"?
With NOT IN. WHERE priority NOT IN ('medium', 'high') returned Printer jam.
How do I add a value to the list later?
Give the check a name when you create the table, with CONSTRAINT <name> in front of CHECK: priority TEXT NOT NULL CONSTRAINT valid_priority CHECK (priority IN ('low', 'medium', 'high')). Since SQLite 3.53.0, ALTER TABLE can then drop the check by its name and add the new list:
ALTER TABLE tickets DROP CONSTRAINT valid_priority;
ALTER TABLE tickets ADD CONSTRAINT valid_priority
CHECK (priority IN ('low', 'medium', 'high', 'urgent'));
After that, a ticket with urgent went in. DROP CONSTRAINT needs the name, so it can't remove a check without one, like the one in this guide, and adding a named check leaves the old check in force: urgent was still refused. The 3.54 shell prints an empty table headed sqlite_fail('cons... after the ADD CONSTRAINT. It isn't an error: Fixed: "sqlite_fail('constraint valid_priority already exists', 1)" After ALTER TABLE ADD CONSTRAINT in SQLite explains it.
Conclusion
CHECK (priority IN ('low', 'medium', 'high')) let the low and high tickets in and refused urgent, so every priority in the table comes from the list.
Additional Resources
- The IN and NOT IN operators — how IN compares a value with a list.
- CHECK constraints — when SQLite evaluates the rule.
