Link to home
Start Free TrialLog in
Avatar of jagguy
jagguyFlag for Australia

asked on

sql null

I have a smallint data type in sql ex 2008.
I want a default value of 0 so what do I do?
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

You could set a default value on the column in the table design, is that what you mean?
in the column definition for the table   have the phrase  DEFAULT 0

create table x  (col1 smallint default 0  , ....)

or
alter table x alter column x smallint default 0

Insert into x (col2,....)     -- but don't name the col1
  values (1,2,...)     -column col1 will get the default

or Insert into x (col1,col2,...)
 values (DEFAULT,1,2,...)   -- using the KEYWORD DEFAULT


is that what you where asking for ?  otherwise please be specific and state what you need to know understand...

use alter table to create a constraint

alter table emp2
add constraint MyColumnDefX default (1) for MyColumn
Avatar of jagguy

ASKER

IN sql management studio what can i do because i am using this an dprefer to use this.
ASKER CERTIFIED SOLUTION
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
in management studio

select new query

and run the code!