SQLite Forum

Suggestion a new dot command (.map)
Login
Alas, I have no SQL script, at least, no SQL script runnable from the SQLite3 CLI.

I built the table using C# calling SQLite3.DLL directly.

I can describe the process:

<b>1. Get a list of tables:</b>

```
SELECT tbl_name
FROM sqlite_master
WHERE type IN (
		'table',
		'view'
		)
	AND tbl_name NOT LIKE 'sqlite%';
```
with CHINOOK.DB, you will get something like this:

```
tbl_name
--------------
albums
artists
customers
employees
genres
invoices
invoice_items
media_types
playlists
playlist_track
tracks
```
<b>2. Iterate the list with this SQL:</b>

```
select datetime('now') as AtDate, 'chinook.db' as Database,* from pragma_table_xinfo('albums');
```

```
AtDate               Database    cid  name      type           notnull  dflt_value  pk  hidden
-------------------  ----------  ---  --------  -------------  -------  ----------  --  ------
2021-01-31 14:53:49  chinook.db  0    AlbumId   INTEGER        1                    1   0
2021-01-31 14:53:49  chinook.db  1    Title     NVARCHAR(160)  1                    0   0
2021-01-31 14:53:49  chinook.db  2    ArtistId  INTEGER        1                    0   0
```

You need to save the results in each iteration into a table.

<b>EITHER</b> create a table with the first iteration with:

```
create table dbMap as select datetime('now') as AtDate, 'chinook.db' as Database,* from pragma_table_xinfo('albums');
```

and append to it with subsequent iterations.

<b>OR</b>

Create a table in each iteration

```
create table tblAlbums as select datetime('now') as AtDate, 'chinook.db' as Database,* from pragma_table_xinfo('albums');

```

If you choose the latter method, you need to collate the individual tables:

```
select * from tblAlbuns
union all
....
select * from tbltracks
select * from tbl tracks

```

You can then redirect the output to a text file, more or less giving you what I [posted here](https://sqlite.org/forum/forumpost/d08a10f875?t=h).

For the iteration, you'll need to use a programming language OR use clever recursive CTEs within the SQLiite3 CLI.