HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How to test if a column definition allows nulls?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
definitionallowscolumntesthownulls

Problem

I have a table with roughly 3000 rows in it and I need to modify a column definition to allow nulls. I have a change script that will perform the change but I would like to be able to re-run the script so that the change will only occur if the column definition hasn't already been changed. How do I test a column definition to identify if the column is NULL or NOT NULL?

Solution

Never mind - found the answer over here

SELECT COLUMNPROPERTY( OBJECT_ID('dbo.spt_values'),'number','AllowsNull')

Code Snippets

SELECT COLUMNPROPERTY( OBJECT_ID('dbo.spt_values'),'number','AllowsNull')

Context

StackExchange Database Administrators Q#6197, answer score: 4

Revisions (0)

No revisions yet.