SQL Server database max row RowVersion - sql-server

Does anyone know if there is a way I can get a database's max RowVersion value? The database I am using is SQL Server 2008.
Thanks.

Are you looking from ##DBTS, which is the last used value? The variable name still references the deprecated TIMESTAMP (TS part) data type but it's the ROWVERSION last value.
SELECT ##DBTS

Related

Postgresql VARCHAR column formatting a UNIQUElDENTIFIER value coming from a SQL Server column

There is a transfer happening between two database.
The first one is a SQL Server. The second one is Postgresql.
I have a column that has a UNIQUEIDENTIFIER in SQL Server and it is sending data to a VARCHAR column in Postgresql. The way the code is implemented expects that column to be a varchar/string.
The issue is that the data gets transferred to that column, but has some formatting issues.
The SQL Server UNIQUEIDENTIFIER value: 27E66FD9-79B8-4342-92A9-3CA87E497E69
The Postgresql VARCHAR value: b'27E66FD9-79B8-4342-92A9-3CA87E497E69'
Obviously, I don't want the extra b'' in there. Is there a way to change this in the database without modifying the data type?

SQL Server syntax for NEWID()

I need some help with some SQL Server 2014 syntax.
I want to use the NEWID() function to create the UUID value in column CareplannersUUID. Each time a record is inserted, I want a new UUID value to appear in column CareplannersUUID.
But I am not sure about the syntax of the command. I think it is something like:
ALTER TABLE CareplannersMembers
ADD CONSTRAINT DF_table_id DEFAULT (NEWID()) FOR CareplannersUUID
I am wondering specifically, is there another value I should add for DF_table_id?
Notes about the table in question:
Table name: CareplannersMembers
UUID column name: CareplannersUUID
Thank you for your help.
Eric
I looked at the similar questions, but am not able to determine, from information presented there, whether or not I am using the correct syntax for my SQL Server statement.

SQL Server convert datetimeoffset to timestamp

I have a datetimeoffset column DateEntry in my SQL Server table. When I want to convert it to a timestamp format with this query :
SELECT CAST(Table1.[DateEntry] AS timestamp)
FROM Table1
I get the following error :
Error : 529- Explicit conversion from data type datetimeoffset to
timestamp is not allowed.
TIMESTAMP in SQL Server has absolutely nothing to do with a date and time, therefore you cannot convert an existing date&time into a TIMESTAMP.
TIMESTAMP or more recently called ROWVERSION is really just a binary counter that SQL Server updates internally whenever row has been modified. You cannot set a TIMESTAMP column yourself, you can just read it out. It is used almost exclusively for optimistic concurrency checks - checking to see whether a row has been modified since it's been read, before updating it.
According to MSDN:
The timestamp data type is just an incrementing number and does not
preserve a date or a time. To record a date or time, use a datetime
data type.
If your are absolutely sure, you can use indirect conversion:
DECLARE #dto datetimeoffset = '2016-01-01 12:30:56.45678'
SELECT CONVERT(timestamp, CONVERT(varbinary(12), #dto))
See also #marc_s's answer.
Try the following script if this this is what you are trying your side
SELECT CAST(CAST(Table1.[DateEntry] AS datetime) as timestamp) FROM Table1

SQL Server 2012 missing RowVersion datatype

I recently restored my database onto a new SQL Server 2012 and notice that all my table columns of RowVersion data types have been changed to binary(8)
In Management Studio when I design the tables, the drop down for the data types no longer even has a choice for rowversion.
I cant find anything from MS other than old information that says it should still exist, or that it is equivalent to binary(8) however binary(8) doesn't auto generate a value like rowversion or timestamp.
Thanks
I haven't actually tried this but it should be something like:
ALTER TABLE YourTable
ALTER COLUMN YourCol rowversion
I think it's by design. Conversion to binary(8) means that any values generated so far are preserved but in order to carry on auto-generating, you need to convert back to rowversion using the above.

Sybase Advantage New AutoInc after SQL Insert

Anyone knows how to retrieve a new AutoInc that gets written after an ODBC INSERT?
Is there a variable I have access to just like SQL Server?
Right now, I'm using :
SELECT MAX(myautoincfield) AS mylastkey FROM anytable
in order to retrieve my new key.
The scalar function LastAutoinc can retrieve it efficiently:
select LastAutoinc(statement) as mylastkey from system.iota;
The global variable ##identity identifies the last value inserted into an IDENTITY column by the current session.
You may do the following:
select ##identity
in order to retrieve the new key.

Resources