How to test a NULL column type - lightw

27-Jul-07 07:02:01
Hi,

I've several tables, in hundreds, with columns not allowing NULL.

Is there a good way to test the column and see if it is defined to allow
NULL or NOT then execute

ALTER TABLE dbo.mytab ALTER COLUMN c1 INT NULL;

Thanks.
button
 
 

How to test a NULL column type - xyb

27-Jul-07 09:07:36
syscolumns table isnullable column indentify what columns can be null.
button
 

How to test a NULL column type - Erland Sommarskog

29-Jul-07 07:33:21
light_wt (lightwt@) writes:

Look at the function columnproperty() in Books Online.

But I get a little worried if you plan to make all your columns nullable.
To start with primary-key columns must not be nullable. But overall, I get
nervous when I see a table definition where all columns are nullable but
the PK (which then typically is an IDENTITY column). No, I am not of the
purist school that claims that nulls should not appear in a database at all,
but I think there is all reason to think twice before you make a column
nullable. For instance, what would it mean if there is a NULL in this
particular column?

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
button
 

How to test a NULL column type - lightw

03-Aug-07 09:34:01
Thanks, xyb and Erland.

you both are experts.
button
 
How to INSERT INTO a temp table