Prefer Strict Tables in SQLite
The author advocates for the use of 'STRICT' tables in SQLite to enforce rigid data typing and prevent common errors like inserting text into integer columns. The post explains how this feature improves database integrity and prevents the storage of invalid data types.
Why it matters
Database integrity is a fundamental aspect of software engineering; adopting strict typing can prevent bugs in data-driven applications.
In short: I prefer strict tables in SQLite because they avoid some datatype problems, such as putting text in number columns.
SQLite has a feature that I think is underrated: strict tables . Strict tables help enforce rigid typing, preventing mistakes like putting text into integer columns. I like them, and wrote this post to promote their use!
To make a strict table, add STRICT to the end of its definition. Like this:
-CREATE TABLE people (name TEXT); +CREATE TABLE people (name TEXT) STRICT; That's it! But what does it do?
Broadly, strict tables help enforce rigid types, like other SQL engines do.
Most significantly, strict tables keep you from inserting the wrong type into a column. For example, SQLite normally lets you put text into an INTEGER column, but not with strict tables.
Get smarter about the news
Sign up free for a feed built around what you actually care about, Dive Deeper research on any story, and the full text of every article.
Create free accountAlready have an account? Sign in