IDENT_CURRENT出错 - 列名无效

时间:2021-06-17 20:31:05

I am trying to update a column in my table which was last inserted. I tried creating this stored procedure:

我正在尝试更新上次插入的表格中的列。我尝试创建此存储过程:

CREATE PROCEDURE [dbo].[msp_AssociateEvent]
(
    @EventId int
)

AS

UPDATE tblFoodMenus set
EventID = @EventId

Where FoodMenuID = IDENT_CURRENT(tblFoodMenus) 

but it gives me this error:

但它给了我这个错误:

Invalid column name tblFoodMenus

列名称tblFoodMenus无效

Am I using IDENT_CURRENT correctly?

我正确使用IDENT_CURRENT吗?

P.S. FoodMenuID is the primary key of tblFoodMenus which is being auto incremented

附: FoodMenuID是tblFoodMenus的主键,它自动递增

2 个解决方案

#1


Table name needs to be in quotes

表名必须在引号中

Where FoodMenuID = IDENT_CURRENT('tblFoodMenus')

#2


Mark Brackett's comment is right on the money - ident_current is not safe to get you the particular identity generated that you are interested in. Almost always you would want to use scope_identity() in the code that does the insert and then pass that around wherever it is needed.

Mark Brackett的评论是正确的 - ident_current对于获得您感兴趣的特定身份是不安全的。几乎总是你想要在执行插入的代码中使用scope_identity()然后将它传递到任何地方需要。

#1


Table name needs to be in quotes

表名必须在引号中

Where FoodMenuID = IDENT_CURRENT('tblFoodMenus')

#2


Mark Brackett's comment is right on the money - ident_current is not safe to get you the particular identity generated that you are interested in. Almost always you would want to use scope_identity() in the code that does the insert and then pass that around wherever it is needed.

Mark Brackett的评论是正确的 - ident_current对于获得您感兴趣的特定身份是不安全的。几乎总是你想要在执行插入的代码中使用scope_identity()然后将它传递到任何地方需要。