sql-serversql-server-2008nullable

Query to check whether a column is nullable


Query to check whether a column is nullable (null values are allowed in the column or not). It should preferably return yes/no or 1/0 or true/false.


Solution

  • You could also use the COLUMNPROPERTY and OBJECT_ID metadata functions:

    SELECT COLUMNPROPERTY(
        OBJECT_ID('SchemaName.TableName', 'U'), 'ColumnName', 'AllowsNull');