How do I add a foreign key to an existing SQLite table?

前端 未结 11 1682
旧时难觅i
旧时难觅i 2020-11-27 12:44

I have the following table:

CREATE TABLE child( 
  id INTEGER PRIMARY KEY, 
  parent_id INTEGER, 
  description TEXT);

How do I add a forei

11条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 12:58

    If you use Db Browser for sqlite ,then it will be easy for you to modify the table. you can add foreign key in existing table without writing a query.

    • Open your database in Db browser,
    • Just right click on table and click modify,
    • At there scroll to foreign key column,
    • double click on field which you want to alter,
    • Then select table and it's field and click ok.

    that's it. You successfully added foreign key in existing table.

提交回复
热议问题