G
Guest
Hi, I just had to deal with the issue described in KB275090. None of the
listed workarounds were satisfactory so I created my own. I feel this method
is preferable when you have the ability to add another trigger to the table.
Here is the code (add it to the bottom of "steps to reproduce"):
-- Figures out what the @@IDENTITY value should be and
-- artificially populates it using dynamic sql.
CREATE TRIGGER TableXX_Ident_Fix_Run_Last ON dbo.TableXX
FOR INSERT
AS
SET NOCOUNT ON
DECLARE @Ident INT
DECLARE @Sql VARCHAR(8000)
SELECT @Ident = MAX(IDCol) FROM Inserted
SET @Sql = '
DECLARE @Table TABLE
(
PK INT IDENTITY (' + CAST(@Ident AS VARCHAR(12)) + ', 1),
test bit
)
INSERT INTO @Table (test) VALUES (1)
'
EXEC(@Sql)
SET NOCOUNT OFF
GO
listed workarounds were satisfactory so I created my own. I feel this method
is preferable when you have the ability to add another trigger to the table.
Here is the code (add it to the bottom of "steps to reproduce"):
-- Figures out what the @@IDENTITY value should be and
-- artificially populates it using dynamic sql.
CREATE TRIGGER TableXX_Ident_Fix_Run_Last ON dbo.TableXX
FOR INSERT
AS
SET NOCOUNT ON
DECLARE @Ident INT
DECLARE @Sql VARCHAR(8000)
SELECT @Ident = MAX(IDCol) FROM Inserted
SET @Sql = '
DECLARE @Table TABLE
(
PK INT IDENTITY (' + CAST(@Ident AS VARCHAR(12)) + ', 1),
test bit
)
INSERT INTO @Table (test) VALUES (1)
'
EXEC(@Sql)
SET NOCOUNT OFF
GO