An Overview of Dot Commands in SQLite

SQLite is a lightweight, self-contained, and highly reliable SQL database engine used widely for developing and testing small-scale applications. One unique feature of SQLite is the set of “dot commands” used in the SQLite command-line interface (CLI) to execute various actions related to database management, navigation, and configuration.

These dot commands are not part of SQL syntax itself but provide a convenient way to manage and interact with SQLite databases.

Continue reading

Fix “Violation of PRIMARY KEY constraint” in SQL Server (Error 2627)

If you’re getting an error that reads something like “Violation of PRIMARY KEY constraint ‘PK_CatId’. Cannot insert duplicate key in object ‘dbo.Cats’. The duplicate key value is (1)” in SQL Server, it’s because you’re trying to insert a duplicate value into a primary key column.

A primary key cannot contain duplicate values.

To fix this issue, you’ll need to change the value you’re trying to insert into the primary key column.

Continue reading

How to Create an Index in SQLite

In database management systems (DBMSs) such as SQLite, indexes can be used to optimize the performance of queries, especially for larger datasets where querying can become time-consuming. An index allows the database to locate rows more quickly without scanning every row in a table.

This article explains how to create an index in SQLite, along with a simple example.

Continue reading

Get the IDENTITY Values that were Generated by an INSERT Statement in SQL Server

The good thing about having IDENTITY columns in SQL Server is that they automatically generate a unique value for every row that’s inserted into a table. This saves us from having to insert our own unique values, and I’m not going to complain about that.

But obvious question you might ask; What if I need to know the value that was generated for each column I just inserted?

Fortunately, the solution may be easier than you think!

Continue reading

Fix Error 137 “Must declare the scalar variable” in SQL Server

If you’re getting SQL Server error 137 that goes something like “Must declare the scalar variable…“, it’s probably because you’re referring to a variable that hasn’t been declared.

If the variable has been declared, it’s possible you’re referring to it incorrectly in the code.

When we use a variable in SQL Server, we must declare the variable first.

To fix this issue, declare the variable. Also be sure to use the right syntax when using it.

Continue reading