我正在使用PGAdminIII數據庫。創建具有引用另一個表的外鍵的表
我已經一個表命名STOCKREGISTER其中包含複合主鍵由三個字段組成,即stockregisterId,的applicationID和日期。
我要創建另一個表STOCK具有引用該領域的外鍵字段stockregisterId STOCKREGISTER的。如果我想創建STOCK表,錯誤消息是shown.The錯誤信息是「沒有獨特的contraint匹配的引用表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
)
下面
是第二table.Here我不能讓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)
)
請分享您試圖使用的模式和代碼 – DevelopmentIsMyPassion 2013-03-04 08:57:53
哪個版本的Sql服務器是這樣的? – DevelopmentIsMyPassion 2013-03-04 12:52:16