ALTER TABLE ADD COLUMN IF NOT EXISTS in SQLite

前端 未结 14 1860
青春惊慌失措
青春惊慌失措 2020-11-28 08:45

We\'ve recently had the need to add columns to a few of our existing SQLite database tables. This can be done with ALTER TABLE ADD COLUMN. Of course, if the table has alre

14条回答
  •  时光取名叫无心
    2020-11-28 09:40

    For those want to use pragma table_info()'s result as part of a larger SQL.

    select count(*) from
    pragma_table_info('')
    where name='';
    
    

    The key part is to use pragma_table_info('') instead of pragma table_info('').


    This answer is inspired by @Robert Hawkey 's reply. The reason I post it as a new answer is I don't have enough reputation to post it as comment.

提交回复
热议问题