我將數據插入到表像這樣:如何獲得插入結果的標識字段?
Insert Into MyTable (Field1, Field2)
Values ('test', 5)
當這種插入發生時,新的行會必須在ID
列的標識值。如果在我的T-SQL代碼中有一個名爲@ID
的變量,如何用T-SQL插入的結果填充@ID
?
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?
哦。我很高興我讀到這個。感謝有關'@@ Identity'和'Scope_Identity()' – 2010-11-11 17:23:55