SQL Server – Getting Not Null Field Properties From a Table

The SQL query below is pretty simple and has helped me quite a bit. Maybe it could help you one day!
Particularly, I am using it to implement my validation classes from a existing database.

1
2
3
4
5
6
SELECT o.Name AS TABLE_NAME,
       c.Name AS Field_Name,
       c.is_nullable AS Allow_Null
FROM sys.columns c
     INNER JOIN sys.objects o ON o.object_id = c.object_id
WHERE o.Name = '<table_name>' AND c.is_nullable = 0

All fields with "NOT NULL" properties will be displayed
Continue reading