This article presents two ways to insert a new line character into a string in SQLite.
This means you can have some text on one line, more text on another line, etc, rather than it being one long line.
Continue readingThis article presents two ways to insert a new line character into a string in SQLite.
This means you can have some text on one line, more text on another line, etc, rather than it being one long line.
Continue readingSQLite doesn’t have a concat()
function like many other database management systems, such as SQL Server’s concat()
and MySQL’s concat()
.
However, that doesn’t mean you can’t concatenate two strings in SQLite.
SQLite has a concatenation operator (||
) that you can use to concatenate two strings.
In SQLite, you can use the instr()
function to return the position of a given character within a string.
The function only returns the position of the first occurrence of the character (if any).
If the character isn’t found, then it returns 0.
If either of the arguments are NULL, then it returns NULL.
Continue readingIn SQLite, you can use the random()
function to generate a pseudo-random number.
This is great, but the value returned is between -9223372036854775808 and +9223372036854775807.
What if you need a random number between 0 and 10? Or say, 1 and 100?
Fortunately you can do this by combining random()
with abs()
and the modulo operator.
SQLite includes a PRAGMA statement that allows you to check for foreign key violations on a whole database or a given table.
The statement is PRAGMA foreign_key_check
, and it works as follows.
If you ever need to enable or disable all CHECK
constraints in SQLite, you can use the ignore_check_constraints PRAGMA statement.
This pragma statement explicitly enables or disables the enforcement of CHECK
constraints. The default setting is off, meaning that CHECK
constraints are enforced by default.
In SQLite, you can create a CHECK
constraint by adding the applicable code within the CREATE TABLE
statement when creating the table.
If a table has a CHECK
constraint on it, and you try to insert or update data that violates the CHECK
constraint, the operation will fail with an error.
SQLite has an interesting way of handling auto-increment columns. By auto-incrementing columns, I mean columns that increment automatically whenever new data is inserted.
This is similar to an IDENTITY
column in SQL Server or an AUTO_INCREMENT
column in MySQL
.
This article explains how to create AUTOINCREMENT
columns in SQLite.
Sometimes you might want to check your “dot command” existing settings in the SQLite command line interface.
Fortunately there’s a .show
dot command that returns various settings and their current values.
This article explains how to restore an SQLite database from within the SQLite command line interface.
There are a few ways to restore a database from the SQLite CLI.
One way to do it is to simply attach a new database using the backup file (or a copy of it). Another way to restore a database is to use the .restore
dot command to restore the database file to your chosen database within SQLite CLI.