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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to alter a null column to not null
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Mohamed Faisal
Yak Posting Veteran

51 Posts

Posted - 10/13/2012 :  04:53:42  Show Profile  Reply with Quote
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.

Edited by - Mohamed Faisal on 10/13/2012 04:54:14

malpashaa
Constraint Violating Yak Guru

Saudi Arabia
264 Posts

Posted - 10/13/2012 :  06:09:04  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000