Skip to content

Instantly share code, notes, and snippets.

@resourcemode
Created September 20, 2019 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save resourcemode/20669f1f2997648509e9459303f58aa0 to your computer and use it in GitHub Desktop.
Save resourcemode/20669f1f2997648509e9459303f58aa0 to your computer and use it in GitHub Desktop.
SQL - list all columns that is not nullable
select schema_name(tab.schema_id) as schema_name,
tab.name as table_name,
col.column_id,
col.name as column_name,
t.name as data_type,
col.max_length,
col.precision
from sys.tables as tab
inner join sys.columns as col
on tab.object_id = col.object_id
left join sys.types as t
on col.user_type_id = t.user_type_id
where col.is_nullable = 0
order by schema_name,
table_name,
column_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment