Get List of All Null and Not Null Columns in SQL Server Database - SQL Server / T-SQL Tutorial Part 53

Scenario:

You are working as SQL Server Developer, You are doing some analysis and want to get the list of all columns in SQL Server Database which are Nullable or Not Nullable.How would you get this information?

Solution:

We can use system views in SQL Server to get this information. Below Query will return us Database Name, Schema Name, Table Name, Column Name,Data Type and IS_Nullable.

SELECT Table_CataLog AS DBName
    ,table_Name
    ,Column_Name
    ,Data_Type
    ,IS_NULLABLE
FROM INFORMATION_SCHEMA.COLUMNS
  --Uncomment the Where Clause if you want to filter the records
  --where TABLE_SCHEMA = 'dbo' and TABLE_NAME = 'TableName' and COLUMN_NAME = 'ColumnName'


How to get list of Nullable and Non-Nullable Columns in SQL Server Database- TSQL Tutorial


No comments:

Post a Comment