我正在使用MS SQL Server。有人请告诉我为什么我的数据库中的我的标识列只是在数字自动增加1时自动跳过数字?首先,我一直在逐行输入数据。最终可能在100个条目之后,它们将不按顺序将它们紧跟在31之后。现在突然它已经从290's跳到了1400's时它应该仍然有序......管理工具仍然显示正确数量的条目,但它只是没有意义这应该是如何计算一个。有人请向我解释一下吗?
<cfif structKeyExists(form, "user_pass")>
<!--- form has been submitted --->
<cffile
action = "upload"
fileField = "filefieldname"
destination = "#expandPath("/webapps/dash/images/")#"
nameConflict = "MakeUnique"
result = "myfile"
/>
<cfset imagePath = myfile.serverDirectory & "/" & myfile.serverFile>
<cfif isImageFile(imagePath)>
<cfquery datasource="test" name="UserRegistration">
INSERT INTO dbo.Users (employee_number, user_name, user_pass, firstname, lastname, position, email, phone_extension, branch, department, status, picture, admin)
VALUES (
<cfqueryparam value='#form.employee_number#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.user_name#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.user_pass#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.firstname#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.lastname#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.position#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.email#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.phone_extension#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='Desoto' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.department#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='Active' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#myfile.serverFile#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='No' cfsqltype='cf_sql_varchar' />
)
</cfquery>
<script>
self.location="../login.cfm";
</script>
<cfelse>
<script>
<!--- not an image file so return some kind of validation message... --->
alert("Not an image file");
self.location="../register.cfm";
</script>
</cfif>
</cfif>
答案 0 :(得分:5)
这些数字保证单调增加,但不是相邻的。 Here是一些相关文档。
通常,标识列也被限制为唯一或主键。但是,如果没有这些限制,它们甚至不能保证是唯一的。
他们确实增加了。奇怪的行为是效率,特别是在并行系统中。
如果需要,在查询时很容易获得没有间隙的顺序值:
select row_number() over (order by id) as sequential_with_no_gaps