Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to alter a null column to not null

Author  Topic 

Mohamed Faisal
Yak Posting Veteran

51 Posts

Posted - 2012-10-13 : 04:53:42
Hi,

I would need a help. I Alter a Table to create a new column:

ALTER CTTable
Add abc Char(3) null;

But the problem is that i need the column to be not Null. how to i go about making it not null.

malpashaa
Constraint Violating Yak Guru

264 Posts

Posted - 2012-10-13 : 06:09:04
Try something like this:

UPDATE CTTable
SET abc = '' --replace '' with your default value.
WHERE abc IS NULL;
GO

ALTER TABLE CTTable ALTER COLUMN abc CHAR(3) NOT NULL;




For us, there is only the trying. The rest is not our business. ~T.S. Eliot

Muhammad Al Pasha
Go to Top of Page
   

- Advertisement -