Link to home
Create AccountLog in
Avatar of reddy_vam
reddy_vam

asked on

How to make a column to accept NULL but stores it as default value

Is there any way to make a column to accept NULL but stores it as default value of Column Property in sql server

Thanks,
Avatar of Muhammad Ahmad Imran
Muhammad Ahmad Imran
Flag of United Kingdom of Great Britain and Northern Ireland image

if you do not enter a value for a column the default will be NULL, you do not need to mention.
Avatar of reddy_vam
reddy_vam

ASKER

but application accepts null values, so I have to convert NULL values to defalut (0)
  select isnull(filedanme,0)
Avatar of Guy Hengel [angelIII / a3]
once you specfiy NULL as value, it will store NULL in the column (if the column does not allow null, then an error would be raised !)
code sample (with colB being the column you refer to):
 insert into yourtable (cola, bolB) values (123, NULL)

Open in new window

if you don't specify the value, it will take the default value, if any, defaulting to NULL (in the latter case, if the column does not allow null, an error would be raised!)
code sample (with colB being the column you refer to):
 insert into yourtable (cola) values (123)

Open in new window


during SELECT, you cannot (easily) fetch the "default" for the column if the value is null...

hope this helps to clarify, if not, please clarify your issue.
ASKER CERTIFIED SOLUTION
Avatar of 8080_Diver
8080_Diver
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
HOw do you insert the records?