KDB knowledge

The trash - UNDROP TABLE

DROP TABLE keeps the table hidden for some days; UNDROP TABLE brings it back with its rows and indexes.

DROP TABLE is easy to type by mistake. With the trash, the table is only hidden: its rows stay where they are, and UNDROP TABLE brings it back. After the keep time (7 days by default) KDB removes it for good.

kdb serve, kdb sql and kdb shell keep dropped tables for --trash-days 7. Programs that use the KDB library set DatabaseOptions::dropped_table_keep_ms (0 = off, the default there).

DROP TABLE and the trash

Syntax:

DROP TABLE [IF EXISTS] <name>                 -- kept in the trash
kdb serve --trash-days 7                      (0 = DROP TABLE removes at once)
DROP TABLE _dropped_<time>_<name>             -- remove one from the trash for good

UNDROP TABLE

Syntax:

UNDROP TABLE <name>

Brings back the newest dropped table with this name: its columns, rows and indexes.

Example: Drop by mistake, then bring it back (sample data: sample)

DROP TABLE live_data;
SHOW DROPPED TABLES;
UNDROP TABLE live_data;
SELECT count(*) FROM live_data;

Result:

DROP TABLE live_data

table 'live_data' dropped; UNDROP TABLE live_data brings it back within 7 days

SHOW DROPPED TABLES

name (STRING)dropped (TIMESTAMP)removed_after (TIMESTAMP)rows (LONG)stored_as (STRING)
live_data2026-10-22T05:44:32.842Z2026-10-29T05:44:32.842Z12_dropped_1792647872842_live_data

(1 row)

UNDROP TABLE live_data

table 'live_data' is back, with 12 row(s)

SELECT count(*) FROM live_data

count(*) (LONG)
12

(1 row)

SHOW DROPPED TABLES

Syntax:

SHOW DROPPED TABLES

The tables in the trash of the current database, newest first.

ColumnMeaning
namethe name the table had
droppedwhen it was dropped
removed_afterwhen KDB removes it for good
rowsrows in it
stored_asits hidden name, for DROP TABLE to remove it at once