Import SQLite records from another database

See how to copy SQLite rows from an already existing (old) database into another database, table by table, using the ATTACH DATABASE built-in feature from within a bash script.

# requires:
# - the old database named as "legacy.sqlite" in the current directory
# - the new database named as "db.sqlite" in the current directory

sqlite3 db.sqlite <<EOF
ATTACH DATABASE 'legacy.sqlite' as 'legacy';

INSERT INTO main.articles (id, title, description) SELECT id, title, description FROM legacy.categories;


Linked Technologies

What it's made of

illustration of Shell

Shell scripting: Automate and streamline your tasks with powerful command-line scripts. Unlock efficiency in every command! Contains bash, zsh, sh, ...

illustration of SQLite

The lightweight and surprisingly fast database option for relational data. Ideal for traditional VPS-style deployments with persistent disk, or in-memory for nontrivial aggregations.

Linked Categories

Where it's useful

illustration of Data Engineering
Data Engineering

Explore the essentials of Data Engineering, delving into how data systems are built and maintained. From organizing data flows to automating complex data processes, discover the tools and techniques that make data easily accessible and useful for everyday projects and insights.

illustration of System Administration
System Administration

Explore the critical world of System Administration, where efficiency and reliability keep computer systems running smoothly. Learn about the tools and techniques for managing servers, networks, and software to ensure optimal performance and security.