选择@@ Identitu或选择MAX() [英] Select @@Identitu or Select MAX()
问题描述
哪个更好?
选择@@ identity或选择MAX()。
@@ identity
将避免需要进行表扫描。
MAX
将扫描表。
可以有更多方法来挑选身份 - 获取SQL中当前身份值的6种不同方法 [ ^ ]。
aciobanita constantin写道:哪个更好?
选择@@ identity或者选择MAX()
嗯...这个问题没有很好的表述。使用@@ identity
或MAX()
的上下文取决于很多因素。
如果您想在表中找到最大值,请使用MAX
函数,但是......如果您想要新增记录,使用@@ identity
。
如需了解更多信息,请参阅:
< a href =http://www.techonthenet.com/access/functions/numeric/max.php> MS Access - MAX()函数 [ ^ ]
检索身份或自动编号值 [ ^ ] + 如何检索MS-Acc中的最后一个自动增量值例如@@ Sql Server中的身份 [ ^ ]
您可能希望使用最新值MAX
函数,但我需要警告你:在多用户环境中,MAX
函数可以返回错误的值。想象一下,添加新记录并返回MAX
值所需的时间以毫秒为单位计算。在MS Access数据库中,更改是在本地进行的,因此...
嗯,正如您所看到的,上面没有一个是更好或更糟。
which is better?
Select @@identity or select MAX().
@@identity
will avoid the need for a table scan.
MAX
would scan the table.
There can be many more ways to pick the identity - 6 Different Ways To Get The Current Identity Value in SQL[^].
aciobanita constantin wrote:which is better?
Select @@identity or select MAX()
Hhmmm... This question is not well formulated. The context of usage of@@identity
orMAX()
depends on many factors.
If you would like to find max value in table, useMAX
function, but... If you would like to newly added record, use@@identity
.
For further information, please see:
MS Access - MAX() function[^]
Retrieving Identity or Autonumber Values[^] + How to retrieve last autoincremented value in MS-Access like @@Identity in Sql Server[^]
You may want to get latest value usingMAX
function, but i need to warn you: in multi-user environment,MAX
function can return wrong value. Imagine, a time needed to add new record and to returnMAX
value is counted in miliseconds. In MS Access database changes are made locally, so...
Well, as you can see, none of above is "better" or "worse".
这篇关于选择@@ Identitu或选择MAX()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!