2

我正在创建一个类似于以下情况的数据库。

表格1:

CustomerType1(列:CustomerId,...)

表2:

CustomerType2(列:CustomerId,...)

表3:

订单(列:OrderId、CustomerId...)

现在,如何将订单表的 customerId 与 CustomerType1 和 CustomerType2 表的 customerId 列关联起来?

(我正在开发一个 Windows Phone 应用程序,所以如果你能帮助我创建类似于上述情况的数据库所使用的属性,那将会很有帮助)

谢谢

4

1 回答 1

2

您的数据库应由 4 个表组成:

 - Customer(CustomerId, common stuff to all customers)
 - CustomerType1(CustomerId, specific stuff to type 1 customers)
 - CustomerType2(CustomerId, specific stuff to type 2 customers)
 - Orders(OrderId, CustomerId, other order stuff)

表列CustomerType1.CustomerId并通过列CustomerType2.CustomerId提供对 Customer 表的引用Customer.CustomerId。也可以通过使用 Orders.CustomerIdCustomer.CustomerId列来实现对 Orders 表和 Customer 表的引用。

为清楚起见,表CustomerType1CustomerType2Orders具有外键约束,如下所示:

FOREIGN KEY (CustomerId) REFERENCES Customer(CustomerId)
于 2013-05-11T14:26:41.450 回答