Click here to Skip to main content
15,908,254 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I have a column in which is integer and nullable.How can I change it to not null and default value as 0 .
Posted

right click table name -> Modify

now select column from list, uncheck 'Allow Nulls'

for set default value,
see, column properties there is Default value or Binding property set it to 0
Save...

now, when ever user pass null in insert query it will take it's value 0

Note : for records already exist in table will not be affect (will not apply automatically 0 instead of null)
so, if you want this in existing records then fire update query


e.g.
SQL
update tbl1 set col1=0 where col1=Null


Happy Coding!
:)
 
Share this answer
 
In SQL Server, a column's default value can be specified as part of the Create Table statement. This default value will be set for the specified column in cases where an insert is performed but this column's value is not set. The given example sets this default as 'MyDefaultValue' for name column.

Example:


Create Table MyTable
(id int not null,
name char(50) default 'MyDefaultValue')
 
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