Click here to Skip to main content
16,012,759 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
ALTER TABLE OrderTypeMaster ADD PckDtlReqd bit DEFAULT (0)

i m using it but it takes default value null

plz help
Posted

Try:
SQL
ALTER TABLE OrderTypeMaster ADD PckDtlReqd bit DEFAULT (0) NOT NULL
 
Share this answer
 
Comments
StackQ 28-Dec-12 7:19am    
it's also working right,but it change column constraint to not null,which is not right according to my requirement.But thnx for help.+5
OriginalGriff 28-Dec-12 7:29am    
Unless you specify NOT NULL, the default value is ignored - it will always insert a null instead of the default when you do not specific a value for this column, unless you specify WITH VALUES in which case the default value will be used for all existing rows in the table (but still not for new ones). Specifying NOT NULL is to only way to persuade SQL to use the default value instead of a null when you INSERT a new row.
StackQ 29-Dec-12 4:33am    
YA,i agree with u.So as u explained,this is new for me,it explore me better,Thnx
OriginalGriff 29-Dec-12 4:46am    
You're welcome!
StackQ 29-Dec-12 4:51am    
thnx, u always help me,and push me to go ahead.thnx for ur support.

Now i have a new question,take a look at it:-

http://www.codeproject.com/Questions/517850/Logicplusbehindplusguidplusinplusc-23pluswindows-3
SQL
ALTER TABLE OrderTypeMaster
ADD PckDtlReqd BIT
GO

ALTER TABLE OrderTypeMaster
            ADD CONSTRAINT DF_OrderTypeMaster_PckDtlReqd
            DEFAULT 0 FOR PckDtlReqd



Regards ,
Vijay
 
Share this answer
 
ALTER TABLE OrderTypeMaster ADD PckDtlReqd bit DEFAULT (0) NOT NULL
 
Share this answer
 
Alter table OrdertypeMaster add PckDtlReqd bit default(0) with values
 
Share this answer
 

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