Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of column names on Sqlite3 database?

Tags:

sqlite

I want to migrate my iPhone app to a new database version. Since I don't have some version saved, I need to check if certain column names exist.

This Stackoverflow entry suggests doing the select

SELECT sql FROM sqlite_master WHERE tbl_name = 'table_name' AND type = 'table' 

and parse the result.

Is that the common way? Alternatives?

like image 381
luebken Avatar asked Jun 03 '09 20:06

luebken


People also ask

How do I get a list of 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. (easier/faster than writing queries for an equivalent result!). sqlite> .

How do I see all columns in SQLite?

Show all columns in a SQLite table. In TablePlus, you can either open the Query Editor and run the statements above, or see all columns from the GUI's table structure view: From the table data view, to switch to structure view, click on the Structure button at the bottom of the window, or press Command + Control + ].

How do I get a list of all columns?

To get the column name of a table we use sp_help with the name of the object or table name. sp_columns returns all the column names of the object. The following query will return the table's column names: sp_columns @table_name = 'News'

How do I print a column name in SQLite python?

Connect to a database using the connect() method. Create a cursor object and use that cursor object created to execute queries in order to create a table and insert values into it. Use the description keyword of the cursor object to get the column names.


1 Answers

PRAGMA table_info(table_name); 

will get you a list of all the column names.

like image 112
nevan king Avatar answered Sep 30 '22 16:09

nevan king