SQL数据关系 [英] SQL Data Relationship

查看:66
本文介绍了SQL数据关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两列,数量和价值.我希望从某种意义上说值与数量相关,即如果数量增加,其价值将与数量保持联系,并且也随之增加.任何想法如何做到这一点? (SQL Server 2008)

I have two columns, Quantity and Value. I want Value to be relational to Quantity in the sense that if quantity goes up its value stays relational to it and also goes up. Any ideas how to do this? (SQL Server 2008)

推荐答案

尝试使用 ^ ]来确定是否使用 UPDATE [^ ]然后在触发器中使用新的操作值相应地更新值"列.
Try using a TRIGGER[^] to find out if Quantity column is updated using UPDATE[^] and then update the Value column with the new manipulated value accordingly in the trigger.


您好,

一种方法是使用触发器.

像这样的东西:

Hello,

One way to do this is to use a trigger.

Something like that:

Create Trigger UpdateData
On Table_1
After Insert, Update
As
Update Table_1 set Value = Quantity * 2;



每次执行更新或插入操作时,都会调用触发器,您可以将自己喜欢的SQL放入触发器中.

http://msdn.microsoft.com/en-us/library/ms189799.aspx [ ^ ]

瓦莱里.



Each time an update or insert will be performed, the trigger will be called, you can put what ever SQL you fancy in the trigger.

http://msdn.microsoft.com/en-us/library/ms189799.aspx[^]

Valery.


这篇关于SQL数据关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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