Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find SQLite Column Names in Empty Table

People also ask

How do I find the column names in SQLite?

Click on Columns and drag it to the query window. This will enumerate the columns names in that given table separated by comma at the cursor position.

Does SQLite have Information_schema?

SQLite doesn't support the idea of different owners of objects so the naming convention for the INFORMATION_SCHEMA views are INFORMATION_SCHEMA_OBJECTNAME.


sqlite> .header on
sqlite> .mode column
sqlite> create table ABC(A TEXT, B VARCHAR);
sqlite> pragma table_info(ABC);
cid         name        type        notnull     dflt_value  pk
----------  ----------  ----------  ----------  ----------  ----------
0           A           TEXT        0                       0
1           B           VARCHAR     0                       0

Execute the query:

PRAGMA table_info( your_table_name );

Documentation


PRAGMA table_info( your_table_name ); doesn't work in HTML5 SQLite.

Here is a small HTML5 SQLite JavaScript Snippet which gets the column names from your_table_name even if its empty. Hope its helpful.

tx.executeSql('SELECT name, sql FROM sqlite_master WHERE type="table" AND name = "your_table_name";', [], function (tx, results) {
  var columnParts = results.rows.item(0).sql.replace(/^[^\(]+\(([^\)]+)\)/g, '$1').split(',');
  var columnNames = [];
  for(i in columnParts) {
    if(typeof columnParts[i] === 'string')
      columnNames.push(columnParts[i].split(" ")[0]);
  }
  console.log(columnNames);
  ///// Your code which uses the columnNames;
});

Execute this query

select * from (select "") left join my_table_to_test b on -1 = b.rowid;

You can try it at online sqlite engine