Default Value for a Column

You have a table with the data, and want to extend it with new column? No problem. But what if you want to initialize existing records to some value? Default Value property will not work in this case. Obviously new records will receive default value, but not old ones. Is there something you can do?

Using Formula Columns for Data Altering article discussing a trick with conversion of the formula to "normal" column. From there you can learn a fact that at the time of conversion the formula is evaluated and the value is instantiated in the normal column. That’s exactly what we need.

Instead of creating new editable column of some type (say, Text), create the column of corresponding Formula type. If you had created the column already, change its type to Formula. Then edit the formula column and provide the expression to calculate default value. It can be either a constant expression such as "A Text" or 3.4, or function call, say Today().

Then, change the formula column type to editable type. You’ll have the records initialized with the value calculated from the formula.

Tweet about this on TwitterShare on Facebook0Share on Google+0