locked
Get value of a Default Constraint element from Model RRS feed

  • Question

  • I'm trying to create a deployment plan modifier that automatically fixes the 'converting a column from Nullable to Not Nullable' problem.

     

    It works by finding all ALTER TABLE steps in the plan that try to alter a column from being Nullable to Not Nullable. When it finds any of these steps it creates & inserts an UPDATE statement prior to the ALTER TABLE statement to automatically set any Nulls in the column being ALTER'ed to a Non-Null value. For this Non-Null value, I want to use the value of the Default Constraint for the column being ALTER'ed.

     

    I've figured out how to create and insert the UPDATE statement prior to the ALTER TABLE statement, so that's all ok and spits out the correct TSQL nicely. But, I'm stuck at how I can find the value of the columns Default Constraint. So far, i've managed to loop through the context.Source model and find the ISQL100DefaultConstraint element for the column being ALTER'ed, but I can't see anything obvious in this ISQL100DefaultConstraint class that allows me to get the actual value of the default constraint. I'm guessing it's something todo with its GetProperty method, but I'm not sure.

     

    Any ideas?

     

    Thanks

    Tuesday, May 11, 2010 2:44 AM

Answers

  • Hi Shane,

    You want the ISqlDefaultConstraint.DefaultExpressionScript property (of type SqlScriptProperty).  Its .Script property will give you the default expression as a string, which you should be able to put into your deployment script.

    • Proposed as answer by Alan Turnquist Tuesday, May 11, 2010 10:01 PM
    • Marked as answer by Shane Hancock Wednesday, May 12, 2010 8:43 AM
    Tuesday, May 11, 2010 10:01 PM