Created
January 31, 2017 21:09
-
-
Save jrotello/fba807e43e8a829a5dee9c3f58fedcb5 to your computer and use it in GitHub Desktop.
TSQL Rowversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
DROP TABLE IF EXISTS [dbo].[MyTab] | |
GO | |
CREATE TABLE [dbo].[MyTab]( | |
[ID] [int] IDENTITY(1,1) PRIMARY KEY NOT NULL, | |
[Value] [nvarchar](50) NOT NULL, | |
[Version] [rowversion] NOT NULL, | |
) | |
*/ | |
/* | |
INSERT INTO MyTab (Value) | |
VALUES | |
('Val1'), | |
('Val2'), | |
('Val3'), | |
('Val4'), | |
('Val5') | |
*/ | |
--SELECT @@DBTS --Current rowversion for the database | |
SELECT * FROM MyTab | |
DECLARE @ver rowversion | |
SELECT @ver = Version FROM MyTab WHERE ID = 2 | |
UPDATE MyTab | |
SET Value = 'Value 2' | |
WHERE ID = 2 | |
AND Version = @ver | |
SELECT * FROM MyTab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment