A directory is a folder. A SQLite database file is usually saved with the file extension .db or .sqlite.
If you try to open the database file by using only its name (for example,
example.db) SQLite will check if that database is in the current directory (folder). If that database is there, it will open it, but if it is not then it will create a new database with that name.
When you are able to set up SQLite the way the Codecademy instructions tell you to, this is easy to avoid because you navigate to the folder containing your database first (using the
cd command in the terminal) and then use the command
sqlite3 to open SQLite.
When you click the
sqlite3.exe file directly, it will open SQLite in the folder where the .exe file is located. For example, if
sqlite3.exe is on your desktop, thats where SQLite will open up.
Let’s say your file structure looks like this:
│ ├── Databases
| | |-- example.db
sqlite3.exe is in your Desktop folder and you double-click it to start the program.
Because you couldn’t navigate to the folder
Databases before launching SQLite, you have to open your database file (
example.db) by using the command
.open Example/Databases/example.db or navigate there through SQLite using this command:
.cd Example/Databases and then open it:
If you were to try opening your database with just
.open example.db from the get-go, SQLite would search for
example.db on the Desktop (where your .exe file is) and when it doesn’t find it, a new database called
example.db will be created there on the Desktop.
Another thing about the
.cd command in SQLite is that it doesn’t handle paths with spaces very well.
Here is a screenshot showing how to open a database (located in Desktop/Sample Database) from a start point of the original downloaded SQLite file. The top left is by clicking the .exe file. Notice how you have to use two separate
.cd commands when there is a space in the file path:
Hopefully this helps illustrate things a little better. If this still seems like gibberish, I would highly recommend using DB Browser instead of the command line.