Check if is column nullable in SQL Server database

Query below check nullability attribute for the column.

Query

select schema_name(t.schema_id) as schema_name,
       t.name as table_name,
       c.name as column_name,
       case is_nullable
            when 0 then 'NOT NULLABLE'
            else 'NULLABLE'
            end as nullable
from sys.columns c
join sys.tables t
     on t.object_id = c.object_id
order by schema_name,
         table_name,
         column_name;

Columns

  • schema_name - schema name
  • table_name - table name
  • column_name - column name
  • nullable - nullability attribute for the column:
    • NULLABLE - is nullable
    • NOT NULLABLE - is not nullable

Rows

  • One row represents one column in the database
  • Scope of rows: all columns in the database
  • Ordered by schema name, table name, column name

Sample results