Finding Table Columns With Default Values

Posted: February 14, 2011 in SQL Server 2005

The following is a quick script to indentify all columns that have a default value in the database.

SELECT       table_name,        column_name, 
         d.definition default_value,        constraint_name
FROM     SYS.TABLES                         t 
         INNER JOIN SYS.SYSCOLUMNS          c  ON t.object_id = 
         INNER JOIN SYS.DEFAULT_CONSTRAINTS d  ON t.object_id = d.parent_object_id 
                                              AND c.colid     = d.parent_column_id

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s