Open a DuckDB .db file? In the DuckDB Web Shell or DBeaver? But how?
For an SQL DDL/DML homework assignment, I'm supposed to open a DuckDB .db file to add new things to it. The assignment says you can supposedly open it in the DuckDB Web Shell, but I don't quite understand that, since the tip says '.open <URL>', but we don't have a URL to the database.
We downloaded the database as a .db file. I've tried opening it in DBeaver, but something's wrong… I can't see any of the things that were supposedly already created.
My problem is that I've never written SQL before, only a little bit in a tutorial using a virtual environment in Jupyter Notebook…"
One way would be to install DuckDB CLI . Download the appropriate version for you and unpack it. I would then copy the database file directly to the directory (for simplicity).
Then open the command line of your operating system (my following code snippets refer to Windows OS) and navigate to the unpacked folder in which the duckdb.exe is located.
Then you can also connect:
If your database file is still in another path, specify the absolute file path instead. It is best enclosed by quotation marks if one of the directory names should contain a space.
Once the client has connected to the database, you should be able to read or write data via SQL. The best starting point would be to first discover what tables are in the database and how they are structured.
The information_schema_tables -View includes eg Information on all available tables in the database:
You can experience the structure of a particular table by using the information_schema.columns -View for the table:
More information information_schema -Views can be checked in the documentation.
As an alternative to this route, DBeaver will make it much easier for you. On your first screenshot, you have already opened the database. If in the left dialog (database navigator) the nodes of eg main or pg_catalog you should also find the tables in the database.
Explicitly relevant to you are, of course, only the tables that have anything to do with hotels.
However, if you still lack knowledge about the structure of database tables (eg what constraints or data types are), I would recommend you to read yourself first. Helpful articles are available on archiving.de . Regarding SQL syntax, you should check DuckDB documentation .
You can add new data to an existing table using INSERT INTO.
Example:
Suppose we have a table hotel staff to list the hotel staff. There are columns First name (VARCHAR), Name (VARCHAR), Content (DECIMAL) and position [VARCHAR]
Adding a new record could look like this:
For further information, I would refer to the DuckDB documentation again.