DB2 to SQLite: Copy Tables into a Database File

Two connections open at once - DB2 on one side, a .db file on the other - and the tables copied with a type map that survives DECIMAL, TIMESTAMP and CLOB, plus a write mode that makes the next run a refresh instead of a duplicate.

Download DBCopier — free trial

Version 3.1.2 · Windows, Linux, macOS · 30-day free trial, then $75 one-time · runs fully offline

DBCopier finishing a DB2 to SQLite copy: rows written per table and the .db file on the right

How to Copy DB2 Tables into SQLite

Step 1: Connect to DB2

Host, port (50000), database and user on the Source DB tab - DB2 needs its client driver, and the driver version decides which authentication DB2 will accept.

Step 1 screenshot

Step 2: Open the SQLite file

On the Target DB tab: a path, not a server. The .db file is created if it does not exist, which is also why the target has no schema dropdown - one file, one namespace.

Step 2 screenshot

Step 3: Pick tables or a query and map the columns

A table, a list, a whole schema, or a SELECT - then the map: DECIMAL to text or to a number, TIMESTAMP to an ISO string, DBCLOB to UTF-8 text.

Step 3 screenshot

Step 4: Run it and check the counts

Progress and the row count per table, with the write mode chosen before the run: create, append, or refresh on a key.

Step 4 screenshot

The Type Map Is the Whole Job

DB2 is a typed, server-side database; SQLite has five storage classes and no enforcement. That gap is where a copy either works or quietly changes the data:

In DB2In SQLite
DECIMAL(18,4), NUMERICNUMERIC affinity; an exact decimal read as a number passes through a double and loses digits past 15, so exact money belongs in a text column
TIMESTAMPstored as text; the format decides whether comparisons and sorts still work - ISO 8601 is the one that sorts correctly as a string
DATE, TIMEtext, same rule
CLOBTEXT - fine, but a CLOB over 1 GB is a value SQLite stores whole and reads whole
BLOB, DBCLOBBLOB; a DBCLOB holds double-byte characters, so it belongs in TEXT
GRAPHIC, VARGRAPHICTEXT with UTF-8 - the conversion happens here, and a missing one produces two-byte mojibake
SMALLINT, INTEGER, BIGINTINTEGER (SQLite's is 64-bit) - a DB2 BIGINT fits
IDENTITYno such thing: copy the values into an INTEGER PRIMARY KEY, or let SQLite assign rowids and accept new ids

Two of these are worth deciding before the first run, not after: money as text (exact) or as a number (fast, lossy past 15 digits), and timestamps as ISO text so that ORDER BY on the column is chronological rather than alphabetical.

DB2 Writes Its Names in Capitals

An unquoted create table employees in DB2 becomes EMPLOYEES, and the schema is part of the name (HR.EMPLOYEES). Two consequences for a copy:

  • The table list is upper case; a filter written as employees finds nothing.
  • SQLite has no schemas inside the file - everything lands in main, so two DB2 schemas with a table of the same name collide on the second copy. Name the target table explicitly (HR_EMPLOYEES) or copy them one at a time.

The same upper-case rule applies to DB2's own catalogue queries: SYSCAT.TABLES, SYSCAT.COLUMNS - which is where you look when a column list has to be checked before mapping.

Copy, Migrate or Sync

Three words, one screen, different intents:

  • Copy - a table or a query into a new table in the .db file. The one-off.
  • Migrate - every table of a schema, in dependency order, usually followed by a check that the row counts match.
  • Sync - the same copy on a schedule with update on a key, so the file tracks the DB2 table instead of accumulating every version of it.

What none of them is: replication. There is no log reading and no trigger - the file is as current as the last run, which is exactly what a scheduled sync with a row count in the log is for.

DB2 to SQLite — Quick Facts

Source
DB2 for LUW (port 50000) - the driver is required on the client machine
Target
a SQLite .db / .sqlite file, created on first use
Modes
create, append, or refresh on a key column
Type map
DECIMAL to text or numeric, TIMESTAMP to ISO text, DBCLOB/GRAPHIC to UTF-8 text
Names
DB2 identifiers are upper case; SQLite has one schema (main)
CLI
the saved task runs without a window - one command, one log

Common Pitfalls when Copying DB2 into SQLite

  • Money as a number: DECIMAL(18,4) in a SQLite column of NUMERIC affinity goes through a binary floating point when it is read as a number - keep it as text if the cents matter.
  • Timestamps as text: 2024-03-15 08:30:00.123456 sorts correctly only if every row uses the same format; a mix of DD.MM.YYYY and ISO does not.
  • Two schemas, one table name: SQLite has one namespace, so the second copy overwrites the first unless the target names differ.
  • IDENTITY columns: copying the values keeps the ids, letting SQLite assign new ones breaks every foreign key that pointed at the old numbers.
  • A CLOB of a gigabyte: SQLite stores and reads the value whole - large objects belong on disk with a path in the row.
  • Appending twice: SQLite enforces the primary key, so a re-run either fails on the duplicates or doubles them, depending on the mode - refresh on a key is the mode that repeats safely.

Which Searches Land Here

What you searchedMeaningPage
db2 to sqlite, copy db2 table to sqlite, migrate db2 to sqlite, sync db2 data to sqlite, convert db2 to sqlitethis pageyou are on it
db2 to mysql, db2 to postgresql, db2 to sql serveranother target engineMySQL / PostgreSQL / SQL Server
sqlite to db2the reverse directionSQLite to DB2
db2 export to ixf / del, then load into sqlitethe export-file routeDB2 to CSV, then CSV to SQLite
a .sql dump of DB2 into sqlitea script rather than a live sourceSQL to SQLite
copy between two sqlite filesSQLite as both sidesCopy between SQLite files

Verify Three Things After the First Copy

  • Row counts on both sides: SELECT COUNT(*) in DB2 against the table in the file - a difference means rejected rows, and the log names the table.
  • One decimal and one timestamp: read them back as they were stored - typeof() in SQLite tells you whether the money went in as text or as a number.
  • The key you would sync on: run the copy twice with refresh mode - the second run must change nothing, which is what makes a scheduled sync safe.

Frequently Asked Questions

How do I copy a DB2 table into SQLite?
Open a DB2 connection and the SQLite file, pick the table or a query, map the columns, choose create or append, then run it.
Is the DB2 driver needed?
Yes - DB2 is a server, so its client driver has to be installed on the machine doing the copy. The SQLite side is just a file.
How is DECIMAL stored in SQLite?
In a column with NUMERIC affinity it becomes a floating point value once read as a number, which loses digits past 15. Map money to text if exactness matters.
Are timestamps kept?
As text - and the format decides whether sorting works: ISO 8601 sorts chronologically as a string, most local formats do not.
What happens to IDENTITY columns?
Copy the values into an INTEGER PRIMARY KEY and the ids survive; let SQLite assign them and every reference to the old numbers breaks.
Two DB2 schemas with the same table name?
SQLite has a single namespace, so the second copy needs a different target table name.
Can it stay in sync on a schedule?
Yes - save the task with update-on-key and run it from Task Scheduler, cron or launchd; the log records the row counts per run.
Can it dump DB2 to a .sql file instead?
Export to CSV or SQL from DB2 and import that; the live copy is faster to set up, the file route is easier to hand over.

Download Withdata DBCopier Now

Start copying DB2 tables into SQLite files in seconds - free trial for Windows, Linux and macOS.

$75 one-time · volume discounts to $55 · 30-day money-back · pricing & licence terms

Download Free Trial