数据库值的增量 [英] Increment In Database Values

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

问题描述

Hello Friends .... !!!



我有一个数据库,其中一些数字在10列。



我想将用户第二列增加1,将第三列增加4,将第四列增加3,将第5列增加6等等....



现在我正在使用这个逻辑....



1)。我将从数据库中检索变量中的值

2)这些变量的增量

3)。更新数据库









请帮帮我我是新手这里!!!!!

Hello Friends....!!!

I have a Database in which some numbers are in 10 column.

I want to increment a users 2nd column by 1, third column by 4 , fourth column by 3 and 5th column by 6 etc....

Now i am using this logic....

1). I will retrieve values in variables from database
2) Increment in these variables
3). Update the data base




Please help me i am new here !!!!!

推荐答案

我会编写一个存储过程来执行它:这样就完成了所有在数据库中完成的,并且没有其他风险人们做同样的事情,你最终得错了。

I would write a stored procedure to do it: that way it is all done within the database, and there is no risk of other people doing the same thing, and you ending up with wrong values.
USE [myDatabase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [proc_addtovals]
AS
UPDATE myTable SET column2=column2+1, column3=column3+4


切勿通过不相关的控件更改值。正如OriginalGriff所示,您可以将增量值设置为SQL语句并让数据库进行计算。



如果增量是用户定义的,那么使用参数定义增量:

Never change the values via irrelevant controls. As OriginalGriff showed, you can set the increment values to the SQL statement and let the database do the calculations.

If the amount of increment is user defined, then use parameters to define the increment:
UPDATE TableName SET Field1 = Field1 + @increment;



请参阅: SqlParameter [ ^ ]


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

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