Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL Server
ALTER TABLE OrderTypeMaster ADD PckDtlReqd bit DEFAULT (0)
i m using it but it takes default value null
 
plz help
Posted 28-Dec-12 1:51am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try:
ALTER TABLE OrderTypeMaster ADD PckDtlReqd bit DEFAULT (0) NOT NULL
  Permalink  
Comments
i}{ Raaz! }{i at 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 at 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.
i}{ Raaz! }{i at 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 at 29-Dec-12 4:46am
   
You're welcome!
i}{ Raaz! }{i at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

ALTER TABLE OrderTypeMaster
ADD PckDtlReqd BIT
GO
 
ALTER TABLE OrderTypeMaster
            ADD CONSTRAINT DF_OrderTypeMaster_PckDtlReqd
            DEFAULT 0 FOR PckDtlReqd
 

Regards ,
Vijay
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

ALTER TABLE OrderTypeMaster ADD PckDtlReqd bit DEFAULT (0) NOT NULL
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Alter table OrdertypeMaster add PckDtlReqd bit default(0) with values
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100