Skip to content

Instantly share code, notes, and snippets.

@jrotello
Created January 31, 2017 21:09
Show Gist options
  • Save jrotello/fba807e43e8a829a5dee9c3f58fedcb5 to your computer and use it in GitHub Desktop.
Save jrotello/fba807e43e8a829a5dee9c3f58fedcb5 to your computer and use it in GitHub Desktop.
TSQL Rowversion
/*
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