what data type i should use for roversion col and can i use less than greater

  • can i use Rowversioncol ( in my database it's synonyme timestamp is used) to run the following query to find all inseted after this @LastKnownRowVersion;

    SELECT * FROM YourTable

    WHERE RowVersionCol > @LastKnownRowVersion;

    data type i should use for @LastKnownRowVersion; why i am asking is because i read this from

    "A nonnullable rowversion column is semantically equivalent to a binary(8) column. A nullable rowversion column is semantically equivalent to a varbinary(8) column."

    https://learn.microsoft.com/en-us/sql/t-sql/data-types/rowversion-transact-sql?view=sql-server-ver17

    q2) what should i do if i have non null roversioncol and if i have null roversion col.

  • If you're using rowversion, use the rowversion data type. Can you use others? Sure. Why? What functionality will you get that you don't already have? What functionality will you lose? It's rowversion. You want to use it as rowversion. Leave it at rowversion.

    Generally speaking, the simplest answers to any problems in SQL Server are the best.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • use varbinary

    @Grant - purpose is normally to use it as "what has changed since last time I did ETL..." so the last rowversion used is stored elsewhere - and can't be rowversion on that case.

  • So you're storing it twice, once as the automated column value and another time as something updated, trigger or what not? I'd go with the varbinary then.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Figured this board out along with Stack,  Leftist not neutral.  It's on.

  • HeftSteady wrote:

    Figured this board out along with Stack,  Leftist not neutral.  It's on.

    Sorry, but what?

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • can i get any example to understand? when to use varbinary.

  • declare @LastKnownRowVersion varbinary(8) = 0x00000000000007D3
    SELECT * FROM YourTable
    WHERE RowVersionCol > @LastKnownRowVersion;

    but both varbinary and binary are the same - only difference is that (as per manual)

    A nonnullable rowversion column is semantically equivalent to a binary(8) column. A nullable rowversion column is semantically equivalent to a varbinary(8) column.

  • i just wanted to understand your scenario, in your case  i can use rowversion and it works.

    why i should i use varbinary(8) ,when i have rowversion datatype.

    declare @LastKnownRowVersion varbinary(8) = 0x00000000000007D3

    SELECT * FROM YourTable

    WHERE RowVersionCol > @LastKnownRowVersion;

  • I'm confused. You said you had two columns, one rowversion and one you're going to update in some way, but you want to store it as it was rowversion? In that case, where you're trying to do two columns, then one of them would be varbinary and you're good to go. If you just have one column, then yeah, use rowversion, not anything else.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply