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.
Database Management Systems
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.
SQLite supports a very limited subset of the ALTER TABLE
statement. The only things you can do with ALTER TABLE
in SQLite is rename a table, rename a column within a table, or add a new column to an existing table.
In other words, you can’t use ALTER TABLE
to add a foreign key to an existing table like you can in other database management systems.
Therefore, the only way you can “add” a foreign key to an existing table in SQLite is to create a new table with a foreign key, then transfer the data to the new table.
There’s more than one way to do this, but there is a recommended way.
Continue readingWhen you create a table in SQLite, you can also create a foreign key in order to establish a relationship with another table.
This article provides an example of creating a foreign key when creating a table in SQLite.
Continue readingIn SQLite, foreign key constraints are not enforced unless foreign key support has been enabled.
Enabling foreign keys involves the following:
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.
SQLite has a group_concat()
function that allows you to concatenate multiple results returned for a column into one.
This is sometimes referred to as “string aggregation”.
For example, when querying a database, instead of having each column’s value output in a new row, you can use group_concat()
to have them output as a comma separated list.
The SQLite substr()
function allows you to return a substring from a string, based on a given starting location within the string.
It requires two arguments, and accepts a third optional argument.
Continue readingIn SQLite, the round()
function allows you to round numbers up or down to a given decimal place.
It returns a floating-point value from the first argument, with the number of decimal places that you specify in the (optional) second argument.
If you don’t provide the second argument, it’s assumed to be 0.
Continue readingThe SQLite lower()
function allows you to convert a string to lowercase characters.
More precisely, it returns a copy of its argument, with all ASCII characters converted to lowercase.
Continue readingThe SQLite upper()
function allows you to convert a string to uppercase characters.
More precisely, it returns a copy of its argument, with all ASCII characters converted to uppercase.
Continue reading