Lose data when renaming field
Ben Mills
Posts: 50
I changed the name of a SmallInt field in my development database. When I ran a compare (using version 6.1.0.53), the UI matched the fields. I presumed this was just based on the fact that is saw 2 fields in the same position of the same type.
The problem is that when I ran the sync, I lost all the data in the field. I had presumed that if the fields were matched in the UI, then the field would just be renamed and I'd keep all the data.
It's not a big deal in this case, but I'm nervous about using SQL Compare to rename a column in the future.
Is this a bug or by design?
The problem is that when I ran the sync, I lost all the data in the field. I had presumed that if the fields were matched in the UI, then the field would just be renamed and I'd keep all the data.
It's not a big deal in this case, but I'm nervous about using SQL Compare to rename a column in the future.
Is this a bug or by design?
Comments
Sorry to hear you're having issues. In what way did the UI match the fields? I expect that in this case SQL Compare would have identified the mismatch as a missing/additional difference. Since there is no way of 'mapping' columns in SQL Compare, it will always drop one column and recreate another. After all, SQL Compare can't second guess whether you've renamed a column, or whether you've deleted an unwanted and added a new one.
SQL Refactor is the right tool to rename a column whilst preserving its data.
http://www.red-gate.com/products/SQL_Refactor/index.htm
Please let us know if this works for you.
Thanks and regards,
David Atkinson
Red Gate Software
Product Manager
Redgate Software
I realize that SQL Compare would have to guess, but I had presumed it had made an assumption based on the field position and data type.
Thanks,
Ben
Ben
If you email the screenshot to me, I'll put it into our bug tracking system. There are some known peculiarities in the side-by-side textual comparison control, so this is most likely to be what's causing the confusion.
My email is david dot atkinson at red-gate.com
I may be wrong, but I'm not aware that column-mapping has ever been in SQL Compare. You may be thinking of SQL Data Compare, which has had this feature since v5.
Regards,
David Atkinson
Red Gate Software
Product Manager
Redgate Software
It's an interesting deficiency in SQL Compare. I was just reading about data migrations in Ruby on Rails. You can create little scripts that rename fields and tables. I think overall SQL Compare is a lot easier to use, but the ability to map fields would be a great additional feature.
I looked at SQL Refactor. It looks like it would be awkward to rename fields on a development machine and make those same changes to my staging or production server. I have a very smooth process for using SQL Compare to push schema changes from my development machine to my production server. I'm not sure that SQL Refactor fits in to that process.
Hi Ben,
SQL Compare does not allow mapping columns. We have been looking into this feature, but it has not made it into the releases. Problems usually arise bacause of computed columns, constraints, forign keys, triggers, etc. and these cannot always be reliably refactored on demand either for comparison of for synchronization purposes.
However, SQL Data Compare supports column mapping, as the above problems are not present during data comparison.
Regards,
Andras
Red Gate Software Ltd.
I rather expected this. SQL Compare tries to preserve data, because around version 3.1 there were a lot of complaints about lost data when columns are renamed and SQL Compare needs to rebuild the table.
It's not entirely consistent, though. SQL Compare checks for similarly-named columns between the tables being migrated first, and if it finds some, it attempts to copy the data from the 'old' to the 'new' column. From the supplied information, I'd say that since the first bit of the two column names are so similar, SQL Compare plays it safe and transfers the data as part of the schema migration.
So SQL Compare sometimes matches columns, but the matching shown in the UI is not necessarily the same as the matching in the synchronization. That seems like a big bug to me.
Ben
The renderer used to display the text comparisons and the one that does the internal work are totally different. There are some limitations in the text comparison -- particularly if the columns in a table are ordinally very far apart.
This isn't a huge issue as I don't rename fields too often, but I'd like to know that this has been acknowledged as a bug and will be fixed in a future release. My vote is to either add a complete field matching feature or to eliminate the matching completely.
Thanks,
Ben
The UI indicates that the fields match, but I'm a little nervous that I'm going to lose my data.
Thanks,
Ben
SQL Server will CAST similar datatypes automatically, following the rules that you find in Books Online. If, for instance, a varchar column is converted to a numeric type, the conversion will succeed if the data in the varchar column can be cast as a number. If any alpha data is present in the column, the conversion will fail and the transaction will roll back.
Text data such as varchar and nvarchar shouldn't be a problem at all unless perhaps the column collations are different. But in any case the SQL should roll back in case of error and place the database back to its' original state.
Please visit the following announcement for more information:
http://www.red-gate.com/MessageBoard/vi ... 1312#51312
David Atkinson
Red Gate Software
Product Manager
Redgate Software