FEE
FEE

Reputation: 309

How does PRAGMA table_info(table-name) work in SQLite database?

I started learning SQLite and read that I can get the column information about any table with the PRAGMA table_info(table-name) command without specifying column names anywhere in the file.

How does PRAGMA know which columns we need for any particular table? Do we have to specify any information about the table in a bin file or environment file?

Upvotes: 2

Views: 5741

Answers (1)

Alex Yu
Alex Yu

Reputation: 3537

Hima, you got everything upside down.

Of course, PRAGMA table_info returns columns of table - it's the purpose of this instruction.

How does it work:

  1. CREATE TABLE NewTable(col1 int, col2 text) statement issued in sqlitedb at some point of time
  2. In consequence of it metadata of sqlitedb is changed: a) 'NewTable' is added in table list, b) ('NewTable','col1'), ('NewTable','col2') is added to column list
  3. Then somebody executes PRAGMA table_info(NewTable) - sqlite looks in metadata and extracts ('col1', 'col2')

Upvotes: 3

Related Questions