How can the same transaction ID be unique within each network?
A composite primary key identifies the tuple, allowing each component to recur in other tuples.
SQLite example and interpretation
Networks A and B can both contain x. Explicit non-null declarations on key columns avoid historical nullable-key behavior in ordinary SQLite tables.
CREATE TABLE tx(net TEXT NOT NULL,id TEXT NOT NULL,PRIMARY KEY(net,id));
INSERT INTO tx VALUES('A','x'),('B','x');
SELECT net,id FROM tx ORDER BY net;Result [["A", "x"], ["B", "x"]]
中文
怎样让同一交易编号在不同网络上独立唯一?
复合主键以字段组合定义记录身份,单个字段可以在其他组合中重复。
SQLite 示例与适用条件
network A 和 B 都可持有编号 x。对普通 SQLite 表显式标记键列非空,有助于避免历史兼容规则导致的空键。
CREATE TABLE tx(net TEXT NOT NULL,id TEXT NOT NULL,PRIMARY KEY(net,id));
INSERT INTO tx VALUES('A','x'),('B','x');
SELECT net,id FROM tx ORDER BY net;结果 [["A", "x"], ["B", "x"]]