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

How to Use SERIAL Functionality on Integer Types Like INT in MySQL

Perhaps you’re familiar with MySQL’s SERIAL type, which is not actually a data type, but a shortcut for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE.

One restriction of SERIAL is that it forces us to use the BIGINT data type, which is fine if you think you’ll need the extra space. But what if you want the same attributes for a smaller integer type, like INT or MEDIUMINT for example?

Enter SERIAL DEFAULT VALUE.

Continue reading

Understanding SQLite’s PI() Function

The PI() function in SQLite returns the mathematical constant π (pi), which is approximately 3.14159265358979. It is used to represent the ratio of the circumference of a circle to its diameter.

The PI() function is commonly employed in mathematical computations, particularly in geometry, trigonometry, and other scientific calculations involving circles and angles.

Continue reading