0

愚蠢的问题我猜...

我想用运输订单实现一个简单的数据库。客户可以发送和接收订单。

一个订单可以有一个日期和两个相对于发货人和发件人的外键。

像这样的东西

Orders(ID,Date,id_sender,id_receiver)

一个简化的客户表将是

Customers(ID,name, surname,city)

我注意到我无法创建两个客户/订单关系,其中一个与外键 id_sender 相关,另一个与 id_receiver 相关。我刚刚尝试使用 OpenOffice DBMS,但在尝试建立第二个关系时出现错误,因为客户和订单之间的关系已经存在。

ID in statement [ALTER TABLE "Orders" ADD FOREIGN KEY("id_sender","id_receiver") REFERENCES "Customers"("ID","ID")

我该怎么解决这个???谢谢,对不起,如果这可能是一个愚蠢的问题。

4

1 回答 1

0

Your statement is trying to create one composite foreign key with two columns, is_sender and id_receiver, both referencing the same column, id on Customers. That's probably not what you want. Instead, you might try to define two separate constraints:

alter table Orders add foreign key (id_sender) references Customers (id);
alter table Orders add foreign key (id_receiver) references Customers (id);
于 2014-02-21T16:32:11.363 回答