Check if a column exists in SQLite

前端 未结 15 500
我寻月下人不归
我寻月下人不归 2020-12-08 07:02

I need to check to see if a column exists and if it doesn\'t exist add it. From my research it looks like sqlite doesn\'t support IF statements and case statement should be

15条回答
  •  抹茶落季
    2020-12-08 07:21

    You cannot use ALTER TABLE withcase.

    You are looking for getting the column names for a table::-

    PRAGMA table_info(table-name);
    

    Check this tutorial on PRAGMA

    This pragma returns one row for each column in the named table. Columns in the result set include the column name, data type, whether or not the column can be NULL, and the default value for the column. The "pk" column in the result set is zero for columns that are not part of the primary key, and is the index of the column in the primary key for columns that are part of the primary key.

提交回复
热议问题