如何在两个表中使用外键 [英] how to use foreign key with two tables
本文介绍了如何在两个表中使用外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个桌子
Hi, I have two tables
TABLE - projectpaymentschedule
COLUMN - ppsID(primary key,auto increment),milestone,completiondate,billingdate,billingrupee,projectid
TABLE - projectpaymentreceipt
COLUMN - pprID(primary key,auto increment),receiptdate,receiptamount,projectid,ppsID(Foreign key)
如何在第二张表中创建外键,并且当我在第一张表中插入数据时自动在第二张表中插入ppsID值.
在此先感谢.
how to make foreign key in second table and i want when i insert data in first table automatically ppsID value inserted in second table.
Thanks in Advance.
推荐答案
尝试以下操作:
Try this:
TABLE - projectpaymentschedule
COLUMN - ppsID(primary key,auto increment),milestone,completiondate,billingdate,billingrupee,projectid
TABLE - projectpaymentreceipt
COLUMN - pprID(primary key,auto increment),receiptdate,receiptamount,projectid,ppsID FOREIGN KEY REFERENCES(ppsID)
Have a look on following threads:
Creating Primary & Foreign keys[^]
SQL-Foreign key[^]
在ADo.Net中,您需要设置数据 ^ ].
System.Data.DataSet.EnforceConstraints
属性应设置为true
.
使用Cascade
选项将允许将更改层叠到相关表.
In ADo.Net you need to setup data constraints[^].
TheSystem.Data.DataSet.EnforceConstraints
property should be set totrue
.
Using theCascade
option will allow changes to be cascaded to related tables.
这篇关于如何在两个表中使用外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文