It is
mentioned in the SQL world that you can’t insert a value into timestamp/rowversion
column. But you actually can, I was surprised to find there was no record of
this workaround on the internet. That said, I looked no more than 15-20 minutes. This was tested on "SQL Server
Edition : 2012 Enterprise".
The problem
with timestamp is that it doesn’t accept an explicit value to a table
Ex.
Create table
#Customer (
ID int ( identity(1,1) ,
Name nvarchar(100),
Address nvarchar(1000),
LastestVersion timestamp )
Name nvarchar(100),
Address nvarchar(1000),
LastestVersion timestamp )
Insert into #Customer
(Name , Address , LastestVersion)
Select top
500 Name , Address , LastestVersion
From Actual_Customer
From Actual_Customer
The above will
error out complaining that a explicit value can’t be added to the #Customer
table due to rowversion.
However if
you define the table on the fly with “SELECT INTO”, SQL server is tricked into believing
the timestamp column is another jack datatype.
SELECT top
500 Name , Address , LastestVersion
INTO #Customer
FROM Actual_Customer
INTO #Customer
FROM Actual_Customer
I haven't spent a lot of time researching in to how "Select INTO" bypass the default behavior, but my hunch, due to the minimal logging with "Select INTO" there is possibly few operations/validations that are overridden.
Conclusion.
It’s time to request Microsoft SQL Server provides an override setting that allows data to be inserted to
timestamp/rowversion datatype.
Comments
Post a Comment