Advertisement
Guest User

Untitled

a guest
Aug 25th, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.61 KB | None | 0 0
  1. USE Test
  2. SET nocount ON
  3.  
  4.  
  5. IF object_id('conc_test') IS NOT NULL
  6.     DROP TABLE conc_test
  7. GO
  8. CREATE TABLE conc_test (id INT);
  9. INSERT conc_test VALUES (1), (2), (3);
  10.  
  11. SET TRANSACTION isolation level serializable
  12.  
  13. DECLARE @id TABLE (id INT)
  14.  
  15. INSERT  @id
  16. SELECT  top 10 id + 3
  17. FROM    dbo.conc_test
  18. ORDER BY
  19.         id DESC  
  20.  
  21. BEGIN TRANSACTION  
  22.  
  23. INSERT  dbo.conc_test
  24.         (id)
  25. SELECT  t1.id
  26. FROM    @id t1
  27. LEFT JOIN    
  28.         dbo.conc_test ct
  29. ON      ct.id = t1.id
  30. WHERE   ct.id IS NULL
  31.  
  32. SELECT  *
  33. FROM    sys.dm_tran_locks
  34. WHERE   request_session_id = @@SPID
  35.  
  36. ROLLBACK TRANSACTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement