如何在pKey字段自动递增时保存FKey字段中的值? [英] How to Save value in FKey Field While Having pKey field Auto increment?

查看:84
本文介绍了如何在pKey字段自动递增时保存FKey字段中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表tblOrder和Tblaccount。

每个订单记录都有一个账户明细

在tblorder我有orderID,这是PK字段和自动增量< brb> tblaccount中的
我有OrderID哪个Fkey不是自动递增并且指的是tblorder

因此,当我下订单时,必须在tblcount orderID字段中保存值,与OrderID相同在tblorder。

解决方案

您可以在表tblorder上使用插入后触发器。


插入到tblaccount(clientId,orderId) ,totalAmount,amountRece,amountBal)值(@ clientid,(从tblorder中选择Top 1 tblorder.orderId ORDER BY tblorder.orderId DESC),@ totalamount,@ amountrec,@ balnce)

 


i have two table tblOrder and Tblaccount.
every order record has an Account Details
in tblorder i have orderID which is PK field and Auto-increment as well
in tblaccount i have OrderID which Fkey which is not Auto-increment and referring to tblorder
So when i Place an order there must be value save in tblcount orderID field same as OrderID in tblorder.

解决方案

You can use an after trigger on insert on table tblorder.


insert into tblaccount(clientId,orderId,totalAmount,amountRece,amountBal) values(@clientid,(select Top 1 tblorder.orderId from tblorder ORDER BY tblorder.orderId DESC),@totalamount,@amountrec,@balnce)


这篇关于如何在pKey字段自动递增时保存FKey字段中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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