nyk0r

IDENTITY_INSERT

Jun 20th, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.38 KB | None | 0 0
  1. -- Snippet enables identity insert if the table [TABLE_NAME] has identity column.
  2.  
  3. IF EXISTS(
  4.     SELECT
  5.         t.object_id
  6.     FROM
  7.         sys.tables t
  8.     INNER JOIN sys.columns c
  9.         ON t.object_id = c.object_id
  10.         and c.is_identity = 1
  11.         and t.name='TABLE_NAME')
  12. BEGIN
  13.     SET IDENTITY_INSERT [dbo].[TABLE_NAME] ON
  14. END
  15.  
  16. -- Don't forget to rollback.
  17. SET IDENTITY_INSERT [dbo].[TABLE_NAME] OFF
Advertisement
Add Comment
Please, Sign In to add comment