为什么我最后一次插入Printer
表中没有返回错误?我认为(希望)由于参照完整性而被拒绝。
代码
CREATE TABLE IF NOT EXISTS
Client (
hostName TEXT PRIMARY KEY,
MACAddress TEXT NOT NULL,
deviceType TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS
Printer (
hostName TEXT NOT NULL REFERENCES Client(hostName),
outputType TEXT NOT NULL,
printerName TEXT NOT NULL,
PRIMARY KEY (hostname, outputType),
FOREIGN KEY (hostName) REFERENCES Client(hostName)
ON DELETE CASCADE
ON UPDATE CASCADE
);
insert into Client (hostName, MACAddress, deviceType)
values ('billlaptop.private.ycc', 'bc:ea:c5:13:b3:09','Client');
insert into Printer (hostName, outputType, printerName)
values ('billlaptop.private.ycc', 'Receipt', 'Thermal');
insert into Printer (hostName, outputType, printerName)
values ('xxxx.private.ycc', 'Receipt', 'Thermal');
select * from Printer;
输出
+--------------------------------------------------+
| hostName outputType printerName |
+--------------------------------------------------+
| billlaptop.private.ycc Receipt Thermal |
| xxxx.private.ycc Receipt Thermal |
+--------------------------------------------------+