【发布时间】:2021-11-25 10:55:51
【问题描述】:
从股票 ubuntu 发行版的命令行。
$ sqlite3
SQLite version 3.31.1 2020-01-27 19:55:54
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .open dumb.db
sqlite> create table a (aid integer primary key, name text);
sqlite> create table b (bid integer, aid integer, name text, foreign key(aid) references a(aid));
sqlite> insert into b values (1,1,'wtf');
sqlite> select * from b;
1|1|wtf
sqlite> select * from a;
sqlite>
在我看来,插入应该失败,因为表 a 中没有 id 值“1”(或任何 id,实际上)。
我是从根本上误解了外键、sqlite 还是两者兼而有之?
是的,I previously asked this for sqlite2 被正确回答为“版本不足”
【问题讨论】:
标签: sqlite