Remark : [MSSQL]Insert실행시 자동증가되는 IDENTITY값 바로 가져오기
1 2 3 |
SELECT @@IDENTITY |
저장프로시저에서 적용
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: 홍길동 -- Create date: 2022-03-02 -- Description: CACHE 저장 -- ============================================= CREATE PROCEDURE CACHE_Save -- Add the parameters for the stored procedure here @IDX int, -- 로그 외래키 @DICSTRING varchar(50), @ENGLISH varchar(50), @KOREAN varchar(50) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; Declare @iDICSTRING int Set @iDICSTRING = (Select count(*) FROM CACHE Where IDX =@IDX and DICSTRING =@DICSTRING) If @iDICSTRING=0 -- Save Begin INSERT INTO [dbo].[CACHE] ([IDX] ,[DICSTRING] ,[ENGLISH] ,[KOREAN]) VALUES (@IDX ,@DICSTRING ,@ENGLISH ,@KOREAN) SELECT @@IDENTITY AS CACHE_IDX end else SELECT 0 AS CACHE_IDX END GO |