Follow sqlserver-dba.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

SQLServer-DBA.com Links

Dba_db2_button

dba-ninja.com

SQL Server DBA Jobs

How to find default values of all SQL Server columns

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

Find SQL Server LOB Columns

How to find SQL Filtered Indexes


Author: Tom Collins (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

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.

Working...

Post a comment on How to find default values of all SQL Server columns


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer