This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing a script to find all default values of the columns in SQL Server.
Sometimes, it requires finding default values of a column which is creating a problem during the data migration.
You can easily find the default values in the table definition script, but if you need the report on all default values of a database, you want only one script for finding all default values.
Using below script, you can get all default values and also if you require finding particular default value, you can add a filter in WHERE clause.
1 2 3 4 5 6 7 8 9 10 11 |
SELECT SO.NAME AS TableName ,SC.NAME AS ColumnName ,SSM.TEXT AS DefaultValue FROM dbo.sysobjects AS SO INNER JOIN dbo.syscolumns AS SC ON SO.id = SC.id INNER JOIN dbo.syscomments AS SSM ON SC.cdefault = SSM.id WHERE SO.xtype = 'U' ORDER BY SO.NAME,SC.colid |