SQLite composite key (2 foreign keys) Link table

前端 未结 4 1124
再見小時候
再見小時候 2020-12-28 18:45

I\'ve read the rather cool styled BNF grammar for the SQLite create table statement

found here: http://www.sqlite.org/lang_createtable.html

I was wo

4条回答
  •  自闭症患者
    2020-12-28 19:14

    Just to complement the first answer, it's a good practice to add a name to constraints, like the code below:

    create table house_items (
        house_id integer not null,
        item_id  integer not null,
        constraint house_items_pk primary key (house_id, item_id),
        constraint house_items_house_fk foreign key (house_id) references houses(id),
        constraint house_items_items_fk foreign key (item_id) references electrical_items(id));
    

提交回复
热议问题