I am starting to use database-projects and struggling with simple tasks. If I would like to add a new column which is NOT NULL
, how can I make it work if there is already data in the table?
I used to write diff-scripts, in such a case I would have written something like:
-- ... ADD COLUMN X ...
-- insert data into x
-- ... ALTER COLUMN X NOT NULL
How would I need to handle such cases with a database-project?
Thx for any tipps sl3dg3
I found finally two possible ways. In a nutshell:
Or
Found here: http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/49bf2a88-d80d-4a9f-970e-728bd530332e/
Or here: http://blogs.msdn.com/b/bahill/archive/2009/03/30/managing-data-motion-during-your-deployments-part-1.aspx
Both means extra work, I was hoping for more support from the framework for such common cases. But at least it can be done like that.
You could also, instead of specifying a DEFAULT value for the column, from the Publish DB Dialog; Go into Advanced->Advanced Deployment Options and check the "Generate Smart Defaults" box.
From the description in VS: Generate Smart Defaults: Automatically provides a default value when updating a table that contains data with a column that does not allow null values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With