zad zad - 1 year ago 65
SQL Question

SQL Server: Find out default value of a column with a query

How can I find out the default value of a column in a table using a SQL query?

By using this stored procedure:

sp_columns @tablename

I get some information on the columns of a particular table but the default value of the columns is missing, How can I get it?

Answer Source

You can find the stored definition with the below (remember to adjust the column and table name to find to be ones relevant to your environment!)

SELECT object_definition(default_object_id) AS definition
FROM   sys.columns
WHERE  name      ='colname'
AND    object_id = object_id('dbo.tablename')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download