Pedro Costa
Pedro Costa

Reputation: 437

How do I find out if a column is required or nullable using a SQL statement?

I need to know if it's possible to know if a Column is "Required" or "Nullable". I can't find any information about this. Is there any Stored Procedure that let's me know if the column is a required field ?

Upvotes: 0

Views: 240

Answers (1)

Jean-François Savard
Jean-François Savard

Reputation: 21004

Oracle

SELECT nullable
FROM user_tab_columns
WHERE table_name = 'TableName'
    AND column_name = 'ColumnName';

SQL-SERVER

SELECT is_nullable 
FROM sys.columns 
WHERE object_id = object_id('TableName') 
    AND name = 'ColumnName';

MySQL

SELECT IS_NULLABLE
FROM information_schema.columns
WHERE TABLE_NAME = 'TableName'
    AND COLUMN_NAME = 'ColumnName';

Upvotes: 3

Related Questions