【发布时间】:2011-05-10 08:52:36
【问题描述】:
如果多个用户同时运行以下查询会发生什么?
INSERT INTO "Retail"."Attributes"("AttributeId","AttributeCode","AttributeName")
VALUES(nextval('"Retail"."CompoundUnits_CompoundUnitId_seq"'::regclass),'COL','Color');
INSERT INTO "Retail"."AttributeDetails"
("AttributeId","AttributeDetailCode","AttributeDetailName")
VALUES
(
currval('"Retail"."CompoundUnits_CompoundUnitId_seq"'::regclass), 'COL-Red', 'Color Red'
),
(
currval('"Retail"."CompoundUnits_CompoundUnitId_seq"'::regclass), 'COL-Blu', 'Color Blue'
),
(
currval('"Retail"."CompoundUnits_CompoundUnitId_seq"'::regclass), 'COL-Gre', 'Color Green'
);
这种方法是否像 SQL SERVER 的 SCOPE_IDENTITY() 一样可靠?任何建议将不胜感激。
【问题讨论】:
-
序列将比 SCOPE_IDENTITY() 更可靠:connect.microsoft.com/SQLServer/feedback/details/328811/…
标签: sql-server postgresql scope-identity nextval