c# - 我可以从两个表中分配外键吗?

标签 c# database windows-phone-8 foreign-keys

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

表1:

CustomerType1(列:CustomerId,...)

表2:

CustomerType2(列:CustomerId,...)

表3:

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

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

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

谢谢

最佳答案

您的数据库应由 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.CustomerIdCustomerType2.CustomerId 通过 Customer.CustomerId 列提供对 Customer 表的引用。此外,还可以通过使用 Orders.CustomerIdCustomer.CustomerId 列来实现对 Orders 表和 Customer 表的引用。

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

FOREIGN KEY (CustomerId) REFERENCES Customer(CustomerId)

关于c# - 我可以从两个表中分配外键吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16498074/

相关文章:

Java JDBC 执行批处理

java - JDBCexecuteUpdate() 仅插入 1 行

xaml - 实现Windows Phone搜索界面

mysql - 连接两个表以替换第二个表中的新值(如果存在)

javascript - 如何在Windows8移动应用程序中禁用触摸覆盖

c# - 哪些 Office 文件查看器和编辑器可用于 Windows Phone 8?

c# - 如何使用 LINQ 选择内部 XML 节点的集合?

c# - WPF 双向绑定(bind)不起作用

c# - 创建嵌套的子 JSON

c# - WPF Treeview项目选择问题