5

Microsoft here mentioned that we should use the rowversion data type over Timestamps. Now inside my SQL Server 2008 R2, I want to create a column with the Rowversion data type. But in my SQL Server 2008 R2 Management Studio, I cannot find such a data type:

enter image description here

Also when I tried altering existing column named timestamp which is of type timestamp using this statement:

ALTER TABLE [SkillManagement].[dbo].[Customer]
ALTER COLUMN timestamp rowversion 

I get this error:

Msg 4927, Level 16, State 1, Line 1
Cannot alter column 'timestamp' to be data type timestamp

Can anyone advise?

EDIT

enter image description here

11
  • 1
    well, timestamp is a synonym of the rwoversion datatype, so...
    – Lamak
    Dec 18, 2014 at 14:11
  • 2
    I mean that timestamp is a synonym of rowversion, it's the exact same data type with another name
    – Lamak
    Dec 18, 2014 at 14:17
  • 3
    You should AVOID using reserved keywords (like TIMESTAMP) as column names - use something more meaningful! Then it'll work.
    – marc_s
    Dec 18, 2014 at 14:48
  • 3
    @johnG timestamp is not meaningful in that context. Unless you think that rowversion contains information about date and time, it's actually quite misleading. Dec 18, 2014 at 15:37
  • 2
    @johnG that doesn't change the fact that you should not use reserved words for column names. Dec 18, 2014 at 15:41

2 Answers 2

23

rowversion is just an alias for timestamp. Under the covers, they are the exact same thing.

If you're using the GUI (prior to 2012), you have to use timestamp. (Peripheral hint: please stop using the GUI.)

But it doesn't stop there. Even if you generate this table using DDL:

CREATE TABLE dbo.x(y ROWVERSION);

The data type in the metadata will be timestamp:

SELECT t.name 
  FROM sys.types AS t
  INNER JOIN sys.columns AS c
    ON c.system_type_id = t.system_type_id
  INNER JOIN sys.tables AS st
    ON c.[object_id] = st.[object_id]
  INNER JOIN sys.schemas AS s
    ON st.[schema_id] = s.[schema_id]
  WHERE st.name = N'x'
    AND s.name = N'dbo'
    AND c.name = N'y';

And if you generate a script for this table, it will also include timestamp:

CREATE TABLE [dbo].[x](
    [y] [timestamp] NOT NULL
) ON [PRIMARY]

And in fact:

SELECT * FROM sys.types WHERE name = N'rowversion';

Results:

----
0 row(s) affected.

So there isn't even a type in the system named rowversion - any DDL that includes it gets parsed and translated before the DDL is even executed against the server.

Microsoft has been a walking contradiction on this since they first introduced the poorly-named data type (which also happens to violate the SQL standard, which dictates that the timestamp data type should be used for date/time data). I asked back in 2007 for this to be properly deprecated. My Connect item is still active (archive)- feel free to vote and, more importantly, comment about how the documentation contradicts the possible usage of the product.

Others have written about this too.

5
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Paul White
    Aug 29, 2017 at 8:24
  • Connect has been moved to UserVoice, you might want to update the link...
    – jmoreno
    Feb 13, 2018 at 14:06
  • @jmoreno Oh, that sounds like an easy task. There are 114 posts on here with links to Connect, and there is no direct translation to UserVoice URLs, so every single one is a manual expedition trying to discover if that item even made it over (because not everything did). I have some real work to do first. :-) Feb 13, 2018 at 14:36
  • Microsoft sort of took your idea of deprecating in Microsoft Connect. Unfortunately they got it backwards, and deprecated Microsoft Connect! don't have to fix bugs if we delete all bug reports
    – Ian Boyd
    Feb 16, 2018 at 16:32
  • This one seems to be at feedback.azure.com/forums/908035-sql-server/suggestions/…
    – jmoreno
    Feb 28, 2018 at 18:32
2

Timestamp is a synonym for the rowversion datatype.

You can find it in this MSDN article.

Microsoft has marked timestamp as deprecated as you can see in the article mention above, but still in SQL Server 2012 Mgmt Studio uses timestamp even if you create the table with the rowversion datatype.

10
  • Yes i already read this article and that why i want to modify the data-type for all my timestamps columns to start using rowversion... so how i can do so ? should i drop exsisting timestamp columns and create new rowversion?
    – john Gu
    Dec 18, 2014 at 14:28
  • No, right now (even in SQL 2012) you can't use the keyword rowversion, you should still use the synonym timestamp. Even if you create a table in SQL 2012 with a rowversion SSMS generates you a create script with the "datatype" timetsamp. Dec 18, 2014 at 14:34
  • so this seems confusing a bit ? MSDN link mentioned that we should consider using rowversion instead of timestamp,, but there is no datatype for rowversion even on sql server 2012 ??/
    – john Gu
    Dec 18, 2014 at 14:42
  • Yeah, it's really confusing. I think the main goal is that you should not use timestamp as name for the column. With timestamp you didn't have to specify a column name, it was automatically set to timestamp, with rowversion you would have to specify a column name. Dec 18, 2014 at 15:03
  • not sure i understand your point,, they are talking about using rowversion instead of timestamp as the data type not the column name...
    – john Gu
    Dec 18, 2014 at 15:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.