Getting Started with the Netflix Sample Database in SQL

If you’re learning SQL or looking for a real-world dataset to sharpen your database skills, the Netflix sample database could be an option. This free, open-source database is based on publicly available information from Netflix’s Engagement Report and Global Top 10 weekly lists, making it both relevant and engaging for practice purposes.

Read more

Using Multiple CTEs in a Single Query

Common Table Expressions (CTEs) are a handy way to break down a complex query into readable, reusable pieces. When you need several intermediate results – say, a filtered set, an aggregation, and a ranking – you can stack multiple CTE definitions together. PostgreSQL, SQL Server, MySQL 8+, and many other engines support this syntax.

Read more

Fix Error “AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY” in SQLite

If you’re getting an error that reads “AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY” in SQLite, it appears that you’re trying to define a column as an AUTOINCREMENT on a column that’s not defined as INTEGER PRIMARY KEY.

SQLite only allows us to use AUTOINCREMENT on INTEGER PRIMARY KEY columns.

To address this issue, be sure to make the column an INTEGER PRIMARY KEY if you need to use AUTOINCREMENT on it.

Read more

How to Use and Store Dates in SQLite

SQLite is a lightweight, self-contained relational database management system that is widely used due to its simplicity and portability. However, one notable aspect of SQLite is its lack of a dedicated DATE or DATETIME storage class. Instead, SQLite stores date and time values as integers, real numbers, or text, depending on how the developer chooses to manage these values.

In this article, we’ll explore how to effectively use and store dates in SQLite, and provide examples that may help you implement date management in your projects.

Read more

2 Ways to Check if a Table has any Partial Indexes in SQLite

In SQLite, a partial index includes only the rows that meet a specified condition, set by a WHERE clause in the index definition. This is different from a regular, or “full,” index, which covers all rows in a table. Partial indexes are helpful when you frequently query specific subsets of data, as they can improve query performance and reduce storage.

If you ever need to check a table to see if it contains any partial indexes, you can use either of the following methods.

Read more

2 Ways to Return the Number of Rows Changed by a SQL Statement in SQLite

SQLite provides several ways to determine how many rows are affected by SQL statements such as INSERT, UPDATE or DELETE.

One way of achieving this is with the changes() function. This function returns the number of rows modified by the most recent SQL statement executed in the current session.

Another way is with the .changes dot command.

In this article, we’ll look at an example that uses these options to get the number of rows changed by various SQL statements.

Read more

Understanding WITHOUT ROWID Tables in SQLite

One feature that sets SQLite apart from most other RDBMSs is the concept of WITHOUT ROWID tables. This is an optimization feature designed to improve performance and reduce storage space for certain use cases.

This article explores what WITHOUT ROWID tables are, how they work, their benefits, and when to use them.

Read more

Find Out if a Table is WITHOUT ROWID in SQLite

One of SQLite’s unique features is the WITHOUT ROWID table, which can be used to optimize performance and storage in specific scenarios.

While it’s easy enough to create a WITHOUT ROWID table (just add WITHOUT ROWID to the definition), how to identify a WITHOUT ROWID table might not be so obvious.

In this article, we’ll start by briefly revising what WITHOUT ROWID tables are and how they differ from ordinary tables. Then we’ll look at how to identify these tables by using SQLite’s PRAGMA commands.

Read more