Columns Defaults

  • I need to determine if a specific column in my database has a default bound to it, and if it does, what the value is. If its the wrong value, I want to replace it with the correct default.

    I have determined how to get the default constraint, but are stuck getting the default value.

    select sysobjects.*

    from sysobjects

    inner join syscolumns on sysobjects.id=syscolumns.cdefault

    where

    objectproperty(sysobjects.id,'IsDefaultCnst')=1

    and

    syscolumns.name='My Column Name'

    What column/table contains the actual default values?


    Robert

  • Thanks, this seems a whole lot easier.


    Robert

  • I found that this doesn't always work.

    I'm dealing with a table with a column taht doesn't appear in your select statement, but surprisingly has a default bound to it in the results of sp_MShelpcolumns 'mytable'.

    When I try to drop the column, I get a message like this:

    The object '<default_name>' is dependent on column '<column_name>'.

    Bye

    Gian

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply