Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I have a question in mind. Would be great if i got a reply

can we add new column with NOT NULL in table which already have records in sql ?

If Yes ,then what would be the most effient way to do this ?


Regards

Anups
Posted

Yes, of course.
You need to specify default value - that is not null.
SQL
alter table mytable add newcolumn int not null default 0
 
Share this answer
 
v2
Kindly try the below qry,


Alter Table TableName Add fieldname CONSTRAINT [Constraint_Name] DEFAULT ((0))



Regards
M.Mani
 
Share this answer
 
Thanks a lot for reply

Regards
Anups
 
Share this answer
 
Comments
gvprabu 27-May-13 5:50am    
if any Questions and Comments, Post in Have a Question or Comments? Area
Not in Solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900