Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 829
user646093 Avatar asked Mar 05 '11 15:03

user646093


People also ask

How do I check if a column is nullable in SQL?

When you have to mention the column in the WHERE clause which contains null, you have two options: 1) Use a function ISNULL on the nullable column and 2) Use an additional OR condition to check the NULLABLE variables like Column IS NULL.

How do I check if a column is nullable in MySQL?

SELECT * FROM yourTableName WHERE yourSpecificColumnName IS NULL OR yourSpecificColumnName = ' '; The IS NULL constraint can be used whenever the column is empty and the symbol ( ' ') is used when there is empty value.

Is SQL nullable?

The IS NULL condition is used in SQL to test for a NULL value. It returns TRUE if a NULL value is found, otherwise it returns FALSE. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.


1 Answers

You could retrieve that from sys.columns:

select  is_nullable  from    sys.columns  where   object_id = object_id('Schema.TheTable')          and name = 'TheColumn' 
like image 147
Andomar Avatar answered Sep 24 '22 12:09

Andomar