Adding field defaults on existing tables

Adding field defaults on existing tables

Post by Steve » Thu, 09 Sep 1999 04:00:00

Hi.  Please help.

I'm trying to write some TSQL that will add default values to already
existing fields in a table.  Though I've see how its done using DEFAULT
objects and dependencies, I'd rather be able to see visually the default
values when I go into Enterprise Manager.  In other words, I want to
store the defaults WITH THE TABLE, not with some obscure object that has
to be 'sp_bindefault'ed, and thus becomes difficult to maintain.

Any advice?

Thanks in advance
-Steve B

Sent via
Share what you know. Learn what you don't.


1. Adding required fields with default values to existing tables

I have a table, Table1, with say 2566 rows of data in it.  Now, a VB
application will add a field to the table at runtime via the following code:

        With OpenDatabase(path, True)
            With .TableDefs!Table1
                .Fields.Append .CreateField("NewField", dbLong)
                With .Fields("NewField")
                    .Required = True
                    .DefaultValue = somedefaultvalue
                End With
            End With
        End With

The field is definately added like I wanted, but the existing data has
nothing in the new field.  How can this be?  If the field is required,
shouldn't the existing data get the default value in the new field?  How can
the field be left Null on all that data?

What the hell, Mel?

2. IE5.5Beta and MSSQL7 Bug

3. How to modified existing field and add new field in existing table for Access database

4. The Perl Clinic - Commercial Support for Perl and Oraperl

5. How to add a default value to a field already existing


7. Adding a BIT field to an existing table

8. Table Field name is a SQL Reserved Word !

9. Can't add bit datatype field to existing table

10. Script DTS or Scripting add field to existing table

11. sp function for adding fields to an existing table

12. Add fields to an existing table

13. Adding a field to an existing table