如何使用SQL语句查明列是否必需或可为空?

时间:2015-04-22 17:28:49

标签: sql sql-server sql-server-2012

我需要知道是否可以知道Column是“Required”还是“Nullable”。我找不到任何关于此的信息。是否有任何存储过程让我知道该列是否为必填字段?

1 个答案:

答案 0 :(得分:3)

<强>的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';