SQL Server 2008:如何为列中的字段赋值并返回列标识

时间:2013-12-29 15:49:35

标签: sql sql-server-2008

我有一个存储过程来更新我的表数据。

update tbl_duty
set Name = @DName,
    Necessity = @DNecessity,
    Payment = @DPayment,
    [Estimation Time] = @DEstimationTime,
    Term = @DTerm,
    [Description] = @DDescription
where 
    Id = "what can I put here"

但我现在不知道如何更新ID列,因为它自己生成(identity列)

任何人都可以帮助我?

我们有类似GETIDENTITY(column name)的内容吗?

1 个答案:

答案 0 :(得分:1)

你想要这样的东西吗?

update tbl_duty
set Name = @DName,
    Necessity = @DNecessity,
    Payment = @DPayment,
    [Estimation Time] = @DEstimationTime,
    Term = @DTerm,
    [Description] = @DDescription
where id = (select max(id) from tbl_duty);

这似乎非常危险。为什么不首先插入具有正确值的记录?