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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 add a new column to a table with conditions

Author  Topic 

pooya1072
Starting Member

13 Posts

Posted - 2013-05-28 : 11:14:39
hi friends
i want to add a column to a table with conditions below :
1- it has a default value=0
2- this column can get null value
3- no constraint should be created

is it possible ?
thanks

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-05-28 : 13:56:39

Individual point explanation:
1) you can set default e.g. create table testing (col int default 0,col2 int)
2) yes it can get nul values
3) when you say default value=0, that means you're defining a constraint.

Overall: the asnwer to "is it possbile" is No, if you want all three points in one table. Since constraint would be created when you define a default value for a column.

Cheers
MIK
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-28 : 14:25:36
ut can still get null value if you've not explicitly made it not nullable in definition and passed an explicit NULL in the insert

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -