我不知道案件部分请帮助我 [英] i do n't under stand the case part please help me

查看:80
本文介绍了我不知道案件部分请帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT ID,name,city,ImageName,ImagePath

FROM aaaa

在ID>时按案例订购0那么

(SELECT MAX(ID)

来自[dbo]。[aaaa])+ 1 ELSE ID END,ID DESC





结果

id

0

3

2

1

SELECT ID, name, city, ImageName, ImagePath
FROM aaaa
ORDER BY CASE WHEN ID > 0 THEN
(SELECT MAX(ID)
FROM [dbo].[aaaa]) + 1 ELSE ID END, ID DESC


result
id
0
3
2
1

推荐答案

如果行ID大于零,则查询将返回最大ID值加一。

如果不是,它将返回零。



这是一个愚蠢的事情去做。如果它在多用户环境中使用,则会导致ID偶尔重复,更常见的是在使用此代码与实际保存新记录之间有明显的时间段。像这样的间歇性问题是一个真正的PITA,一旦数据库上线就能找到,应该不惜一切代价避免。相反,在保存数据时分配id,而不是之前 - 如果必须,请使用Identity规范,或者使用GUID。
If the row ID is greater than zero, then the query will return the maximum ID value, plus one.
If it isn''t, it will return zero.

And it''s a stupid thing to do. If it is used in a multiuser environment, it leads to IDs being duplicated occasionally, more frequently is there is any noticeable time period between the use of this code and the actual save of the new record. Intermittent problems like this are a real PITA to find once a database goes live, and should be avoided at all costs. Instead, allocate an id when you save the data, and not before - use the Identity specification if you have to, or use GUIDs instead.


这篇关于我不知道案件部分请帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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