相关疑难解决方法(0)

如何获取插入产生的Identity字段?

我要将数据插入到表中,如下所示:

Insert Into MyTable (Field1, Field2)
           Values   ('test', 5)
Run Code Online (Sandbox Code Playgroud)

发生插入时,新行将在ID列中具有标识值.如果@ID在我的T-SQL代码中调用了一个变量,如何填充@IDT-SQL插入的结果?

Declare @ID int

Insert into MyTable (Field1, Field2)
             Values ('test', 5)

--//How do I populate @ID with the value of ID of the record that was just inserted?
Run Code Online (Sandbox Code Playgroud)

sql t-sql sql-server stored-procedures

4
推荐指数
1
解决办法
328
查看次数

标签 统计

sql ×1

sql-server ×1

stored-procedures ×1

t-sql ×1