我正在使用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