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.
Related
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?
i have table with data and now i want to change its column dataype from varchar to text,
ALTER TABLE ver_table ALTER COLUMN field text;
unfortunately it gives the
SQL Error [1088] [S1000]: Cannot find the object "ver_table" because it does not exist or you do not have permissions.
Cannot find the object "ver_table" because it does not exist or you do not have permissions.
but the table actualy exists with data.
The query should support in all versions of Sql server.
Is any other to achieve this without losing of data, i mean any procedure ?
Please do correct me.
thanks
You should avoid using the text data type.
Important
ntext, text, and image data types will be removed in a
future version of Microsoft SQL Server. Avoid using these data types
in new development work, and plan to modify applications that
currently use them. Use nvarchar(max), varchar(max), and
varbinary(max) instead.
Source: Microsoft Docs.
I have generated classes (DbContext) modelling my db (SQL Server 2008 R2), and in most of my tables I have the standard ModifiedDate and CreatedDate (No Nulls). Each of these has a default of getdate() in SQLServer, and I have a trigger to update ModifiedDate on any updates.
The generated views included the ModifiedDate and CreatedDate fields, which I don't want (the user shouldn't see these), so I've taken these out, but when adding a new entry using the generated Create view, I get the error "The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value".
I then added some default values, and it did add the record, but naturally it added my entered values, and not the SQL getdate() values, which I'd prefer (I want it to show the server time). Checking the object (db.SaveChanges()) the fields have a value of {1/01/0001 12:00:00 AM}.
How can I use these models without entering dates??? I've searched but haven't found my answer... ;-(
This is a common problem in both Entity Framework and Linq to SQL:
In Linq-To-SQL the model doesn't know about the default values, and so attempts to assign them as "null" - which in this case isn't acceptable. To fix this, open the DBML file and set the "Auto Generated Value" option to "true" for the fields in question.
In Entity Framework it's a little different: you set the "StoreGeneratedPattern" on the field to either "Identity" or "Computed". Here's the description:
http://msdn.microsoft.com/en-us/library/system.data.metadata.edm.storegeneratedpattern.aspx
EF will do this automatically for Identity type fields, but not for default value/not null fields. You may want to set your CreatedDate as "Identity" (updated only on insert) and your ModifiedDate as "Computed" (updated on insert and update).
The byproduct of this is that you then will not be able to set the fields via Linq at all - but that's fine in your use case, I think.
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
I have a zipcode field in a database that I just took over. Previously, it was set as a numeric field with 18 precision but I am trying to convert it over to varchar(10).
I need to make this change because the linq fields are coming in as decimal and are causing issues and i want to change the linq fields to simply be strings.
I tried this in SQL server enterprise manager but i get this error, saying:
that the table will have to be dropped and recreated. you have either made changes to a table that can't be recreated or enable the option to prevent saving changes that require a table recreation
Any suggestions?
to enable that option in SQL management studio uncheck the following option...
Tools / Options / Designers / Table and Database Designers / Prevent saving changes that require table re-creation
You could also run an alter statement to change your datatype (as long as all of your data will fit in a varchar(10) column).
ALTER TABLE MyTable
ALTER COLUMN MyZipCodeColumn VARCHAR(10)
Are you using MS-SQL 2008? Changes that require the table to rebuilt are blocked by default.
Click Tools->Options, then Designers. Uncheck "Prevent saving changes that require table re-creation".
Then you can change your column using the designer.
Screenshots on how to do it:
http://pragmaticworks.com/community/blogs/brianknight/archive/2008/06/04/sql-server-2008-designer-behavior-change-saving-changes-not-permitted.aspx