如何增加价值 [英] How to increament value

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

问题描述

Declare @UID varchar(30)
Declare @UserId varchar(30)
Set @UID='0'
Set @UID= @UserId
SET @UserId = @UID+1;
Select @UserId as u





我尝试过:



i想知道每次执行价值增加怎么办



喜欢

1

2

3

i不想使用身份我希望以上查询通过增量

所以请帮助我



What I have tried:

i want to know how to do on every execute value increase

like
1
2
3
i do not want to use identity i want this above query through increment
so please help me

推荐答案

不要自己动手,使用IDENTITY。我知道,我知道,你不想 - 但它让生活变得更加轻松和安全。问题是SQL服务器和MySql都是多用户系统,你试图自己动手,你必须记住,不同的用户也可以尝试增加相同的值 - 如果你不这样做然后你开始得到真正令人讨厌的间歇性错误,几乎无法发现,更不用说修复了!



使用IDENTITY意味着SQL为你工作,并且在幕后透明地处理所有多用户内容。



你永远不应该选择下一个值,因为当用户插入行时它可能无效 - 前 - 选择ID是一件危险的事情,如果你不是真的那么小心,你的数据库真的会搞砸。
Don't do it yourself, use IDENTITY. I know, I know, you don't want to - but it makes life a whole lot easier and safer. The problem is that SQL server and MySql are both multiuser systems, and it you try to "do it yourself" you have to bear in mind at at any time a different user could also be trying to increment the same value - if you don't then you start to get really nasty intermittent errors which are next to impossible to spot, let alone fix!

Using IDENTITY means that SQL works it out for you, and handles all the multiuser stuff transparently behind the scenes.

And you should never SELECT a "next value" because it may not be valid when the user INSERTs the row - pre-selecting ID's is a dangerous thing to do, and can really mess up your DB if you aren't really, really careful.


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

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