20 March,2023 by Tom Collins
Question: Do you have a sql query to check every sql server database column and identify if a default value is applied to the column?
Answer : This query example will return 3 columns - table, column , and default column value
use [myDB] SELECT so.NAME AS "TABLE", sc.NAME AS "COLUMN", sm.TEXT AS "DEFAULT COLUMN VALUE" FROM dbo.sysobjects so INNER JOIN dbo.syscolumns sc ON so.id = sc.id LEFT JOIN dbo.syscomments sm ON sc.cdefault = sm.id WHERE so.xtype = 'U' AND sm.TEXT IS NOT NULL ORDER BY so.[name], sc.colid
Read more on finding other SQL database objects
List Foreign Keys referencing tables in SQL Server
What are the triggers in SQL Server
How to find all identity columns in SQL Server
How to find computed columns on a SQL Server table
How to find SQL Filtered Indexes
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |