Guest User

Untitled

a guest
May 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. CREATE TABLE #a(identity_column INT IDENTITY(1,1), x CHAR(1));
  2.  
  3. INSERT #a(x) VALUES('a');
  4.  
  5. SELECT SCOPE_IDENTITY();
  6.  
  7. ----
  8. 1
  9.  
  10. INSERT #a(x)
  11. OUTPUT inserted.identity_column
  12. VALUES('b'),('c');
  13.  
  14. ----
  15. 2
  16. 3
  17.  
  18. CREATE TABLE ReverseIdent (
  19. id int IDENTITY(9000,-1) NOT NULL PRIMARY KEY CLUSTERED,
  20. data char(4)
  21. )
  22.  
  23. INSERT INTO ReverseIdent (data)
  24. VALUES ('a'), ('b'), ('c')
  25.  
  26. SELECT * FROM ReverseIdent
  27.  
  28. SELECT IDENT_CURRENT('ReverseIdent') --8998
  29. SELECT MAX(id) FROM ReverseIdent --9000
  30.  
  31. SET IDENTITY_INSERT ReverseIdent ON
  32.  
  33. INSERT INTO ReverseIdent (id, data)
  34. VALUES (9005, 'd')
  35.  
  36. SET IDENTITY_INSERT ReverseIdent OFF
  37.  
  38. SELECT IDENT_CURRENT('ReverseIdent') --8998
  39. SELECT MAX(id) FROM ReverseIdent --9005
Add Comment
Please, Sign In to add comment