Adding NOT NULL columns to tables with data
LittleColin
Posts: 16
Newbie question:
Can SQL Compare support the following for static data tables (by static I mean that the source database contains a superset of the data that is in the destination database and the source is the master of this data):
* Spot that a NOT NULL column has been added to the source
* Create it as a NULL allowed column in destination prior to data migration
* Include the data migration script (e.g. from SQL Data Compare)
* Change the NULL columns created above to the desired NOT NULL
Can SQL Compare support the following for static data tables (by static I mean that the source database contains a superset of the data that is in the destination database and the source is the master of this data):
* Spot that a NOT NULL column has been added to the source
* Create it as a NULL allowed column in destination prior to data migration
* Include the data migration script (e.g. from SQL Data Compare)
* Change the NULL columns created above to the desired NOT NULL
Comments
Your last step of converting the column back to NOT NULL would surely fail as any pre-existing records in the target will have NULL in the new column and this is incompatible with changing it to NOT NULL.
The solution would have to be to allow the user to specify a default value for existing records in the target.
David Atkinson
Product Manager
Red Gate Software
Product Manager
Redgate Software
(note that I haven't yet tried the SQL Data Compare to see if it can add data for the added columns but am assuming it can - as opposed to only working on a row added or removed basis - or am I wrong about that?)
But thanks for your reply - am looking forward to this feature being added.
http://www.cybercohesion.com
Therefore the schemas would need to be synched first in SQL Compare, which is not as data-aware as it could be so it will complain about the NOT NULL column. Ideally it should read the source table and spot that values for these additional columns already exist and use these.
In the meantime your best bet is to temporarily change the source column to be NULL, synch the schema using SQL Compare, synch the data using SQL Data Compare and set the source column back to NOT NULL. It's not as smooth as it should but hopefully we can improve matters in a later release.
Thanks for bringing this to our attention,
David Atkinson
Red Gate Software
Product Manager
Redgate Software
http://www.red-gate.com/MessageBoard/vi ... 1312#51312
Let us know whether this meets your expectations.
David Atkinson
Red Gate Software
Product Manager
Redgate Software