如何在两个表中使用外键 [英] how to use foreign key with two tables

查看:98
本文介绍了如何在两个表中使用外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个桌子

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)



看看以下线程:
SQL外键 [



Have a look on following threads:
Creating Primary & Foreign keys[^]
SQL-Foreign key[^]


在ADo.Net中,您需要设置数据
In ADo.Net you need to setup data constraints[^].
The System.Data.DataSet.EnforceConstraints property should be set to true.

Using the Cascade option will allow changes to be cascaded to related tables.


这篇关于如何在两个表中使用外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆