You can ask SQLite to give you the name suitable for use as a temporary database file using the [sqlite3_file_control(SQLITE_FCTRL_TEMP_FILENAME)][1] interface. Or you can create your own unique temporary filename using an SQL statement like this: > SELECT hex(randomblob(32)); Then simply run ATTACH with that filename. The new database will be created automatically. [1]: https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntltempfilename