SQL : Test if a column has the "Not Null" property
Is there a simple que开发者_运维百科ry to return whether a specific column allows nulls?
I want to change this as part of a DB upgrade script.Alternatively, is it better to just change it, even if its already set?
Edit : This is for SQL Server (needs to support 2000 or later)
Any particular RDBMS?
In SQL Server
use master
SELECT COLUMNPROPERTY( OBJECT_ID('dbo.spt_values'),'number','AllowsNull')
Or (more standard)
select IS_NULLABLE
from INFORMATION_SCHEMA.COLUMNS
where TABLE_SCHEMA='dbo'
AND TABLE_NAME='spt_values'
AND COLUMN_NAME='number'
精彩评论