我正在使用 PGAdminIII 数据库。
我有一个名为STOCKREGISTER的表,其中包含由三个字段组成的复合主键,即stockregisterId、applicationId 和 date。
我必须创建另一个表STOCK,它有一个引用 STOCKREGISTER 的字段stockregisterId的外键字段。如果我尝试创建STOCK表,则会显示一条错误消息。错误消息是“引用表没有唯一的约束匹配键STOCKREGISTER”。下一步我必须采取什么步骤
第一张桌子
CREATE TABLE stock_register
(
stock_register_id bigint NOT NULL,
application_id bigserial NOT NULL,
production_date date NOT NULL,
opening_bal bigint DEFAULT 0,
quantity_produced bigint,
total_quantity bigint
CONSTRAINT primarykey PRIMARY KEY (stock_register_id, application_id, production_date),
CONSTRAINT "foreignKey" FOREIGN KEY (application_id)
REFERENCES application (application_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
下面是第二张表。这里我不能将 stock_register_id作为外键
CREATE TABLE Stock
(
stock_id bigint NOT NULL,
stock_register_id bigint,
dimension bigserial NOT NULL,
CONSTRAINT "stockid" PRIMARY KEY (stock_id)
)