我在 Visual Studio - VB.NET 中工作.
I'm working in Visual Studio - VB.NET.
我的问题是我想删除 SQL Server 中的特定行,但我唯一的唯一列是一个自动递增的标识.
My problem is that I want to delete a specific row in SQL Server but the only unique column I have is an Identity that increments automatically.
我的工作流程:
1.我在列中添加了一行(身份正在递增,但我不知道数字)
2.我想删除上一行
My process of work:
1. I add a row in the column (the identity is being incremented, but I don't know the number)
2. I want to delete the previous row
是否存在每条新记录都有的唯一 ID?可能我的表有 2 条完全相同的记录,只是序列(身份)不同.
Is there a sort of unique ID that every new record has? It's possible that my table has 2 exactly the same records, just the sequence (identity) is different.
任何想法如何处理这个问题?
Any ideas how to handle this problem?
SQL Server 有几个函数可以返回最后一行的生成 ID,每个函数都有自己特定的优点和缺点.
SQL Server has a few functions that return the generated ID for the last rows, each with it's own specific strengths and weaknesses.
基本上:
@@IDENTITY 如果您不使用触发器SCOPE_IDENTITY() 适用于您明确调用的代码.IDENT_CURRENT(‘tablename’) 适用于所有范围的特定表.@@IDENTITY works if you do not use triggersSCOPE_IDENTITY() works for the code you explicitly called.IDENT_CURRENT(‘tablename’) works for a specific table, across all scopes.在几乎所有情况下,SCOPE_IDENTITY() 都是您所需要的,并且使用它是一个好习惯,而不是其他选项.
此处.
In almost all scenarios SCOPE_IDENTITY() is what you need, and it's a good habit to use it, opposed to the other options.
A good discussion on the pros and cons of the approaches is also available here.
这篇关于SQL Server 中是否每条记录都有唯一的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
我应该使用什么 SQL Server 数据类型来存储字节 What SQL Server Datatype Should I Use To Store A Byte[](我应该使用什么 SQL Server 数据类型来存储字节 [])
解释 SQL Server 中 sys.objects 中的类型代码Interpreting type codes in sys.objects in SQL Server(解释 SQL Server 中 sys.objects 中的类型代码)
Typeorm .loadRelationCountAndMap 返回零Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
MS SQL:ISDATE() 是否应该返回“1"?什么时候不能MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否应该返回“1?什么时候不能投射为日期?)
将一天的名称转换为其整数表示Converting the name of a day to its integer representation(将一天的名称转换为其整数表示)
如何在 SQL Server 中将 nvarchar m/d/yy 转换为 mm/dd/yHow to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中将 nvarchar m/d/yy 转换为 mm/dd/yyyy?)