An Overview of the LIKELIHOOD() Function in SQLite

SQLite is a lightweight, serverless database engine widely used for its simplicity and flexibility. Among its many functions, the likelihood() function is a handy option that allows you to influence query planning by providing hints about the probability of certain conditions being true.

This article explores the details of the likelihood() function, its syntax, use cases, and a practical example to demonstrate its application.

Continue reading

Understanding Julian Day

Julian day is a concept you might occasionally encounter in SQL code or database operations, particularly when working with date and time functions. While it may seem esoteric at first, understanding Julian day can be incredibly useful for handling date calculations, especially in fields like astronomy, data analysis, and historical research.

This article looks at the origins, calculations, and practical applications of Julian day, including examples of converting between Julian day and other date formats in SQL.

Continue reading

Fix Error: unknown datatype for (columnname): “DATE” in SQLite

If you’re getting an error that reads something like “unknown datatype for (columnname): “DATE”” in SQLite, it appears that you’re trying to define a column as a DATE type in a strict table.

SQLite doesn’t support the DATE type, however, this error should only occur on strict tables (i.e. a table defined as STRICT).

To fix this issue, either use a supported data type or make the table a regular (non-strict) table.

Continue reading

Data Types that SQLite Allows for Strict Tables

SQLite is a lightweight, self-contained SQL database engine known for its simplicity and versatility. In version 3.37.0, SQLite introduced strict tables, offering stricter type enforcement compared to its regular tables.

This feature allows developers to define tables with precise data types, ensuring better data consistency.

In this article, we’ll look at the six supported data types for strict tables—INT, INTEGER, REAL, TEXT, BLOB, and ANY—and provide simple examples to illustrate their usage.

Continue reading

Why the Primary Key Might Not Appear in PRAGMA index_list() in SQLite

In most relational database management systems (RDBMSs) the PRIMARY KEY is used to define the unique row identifier for a table. But in SQLite, not all primary keys are handled the same way when it comes to indexing.

Depending on how the primary key is defined in a table, it may or may not show up in the list of indexes returned by the PRAGMA index_list() command. In particular, when the primary key is an INTEGER PRIMARY KEY, SQLite doesn’t explicitly create a separate index for it.

This article will explain why this happens and provide examples with different types of primary key definitions.

Continue reading

An Introduction to Strict Tables in SQLite

SQLite is widely known for its simplicity, flexibility, and lightweight architecture. One feature that sets it apart from most other SQL databases is its dynamic typing system, which allows columns in a table to store data of any type, regardless of their declared type.

While some developers welcome this departure from the traditional SQL approach, others find it extremely problematic, due to its non-enforcement of data types, which could potentially lead to data integrity issues.

Continue reading

How to Effectively “Back Up” All Deleted Rows When Using DELETE in SQL Server

Deleting rows in a SQL database can sometimes be a nerve-racking experience. What if you’re deleting the wrong rows? Or what if the business later tells you they want their data back?

Fortunately SQL Server provides us with an easy way to essentially “back up” any rows affected by a DELETE operation to a table.

This article looks at using the OUTPUT ... INTO clause to save a copy of deleted rows to another table.

Continue reading