all groups > sql server new users > november 2006 >
You're in the

sql server new users

group:

Setting a default value for a bit field?



Setting a default value for a bit field? _adrian
11/25/2006 2:32:17 PM
sql server new users: I've got a table where one of the fields is "bit" .. and I need to set it so
that if no value is inserted with the new record, the value of that field
should be "0" (zero) .. but instead, the table shows <null> instead!!! This
is wreaking having with my ASP.. Entering in 0 by itself in the "Default"
value window of that field doesn't work.. it still creates nulls.. what do I
need to do so that the field enters 0 instead of null?

Re: Setting a default value for a bit field? Arnie Rowland
11/25/2006 5:10:52 PM
This is one method.


ALTER TABLE MyTable
ADD CONSTRAINT df_MyBitColumnDefault DEFAULT 0 FOR MyBitColumn

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous

You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf


[quoted text, click to view]

Re: Setting a default value for a bit field? _adrian
11/25/2006 5:37:58 PM
Hi Arnie.. sorry, a relative newbie here.. I was thinking there was a way to
do it in enterprise manager...

Re: Setting a default value for a bit field? Arnie Rowland
11/25/2006 6:25:39 PM
You'll find most experienced folks avoid Enterprise Mangler -for lots of
good reasons.

However, I think that you can right-click on the table, select [Design
Table], and then select the column and add the default value at the bottom
where it indicates. Be warned, if this is a large table,this bass-ackward
method may take some time to complete.

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous

You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf


[quoted text, click to view]

Re: Setting a default value for a bit field? _adrian
11/26/2006 4:03:18 PM
Hi Arnie.. I tried the method you described, and the value I'm trying to set
is 0, but when the record is created, if no other variable is inserted in
the table, it shows up as NULL, not 0.. which ASP reads differently.

Umm.. and if I don't use Enterprise Mangler.. what should i be using? Please
pardon my ignorance...

Re: Setting a default value for a bit field? Arnie Rowland
11/26/2006 4:17:51 PM
Did you 'unselect' the [Allow NULLs] checkbox?

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous

You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf


[quoted text, click to view]

Re: Setting a default value for a bit field? _adrian
11/27/2006 2:59:31 PM
Thats an excellent question.. and I'll try it.. thanks .. its always the
simple things

Re: Setting a default value for a bit field? Hugo Kornelis
11/28/2006 12:42:44 AM
[quoted text, click to view]

Hi adrian,

Could you describe HOW you enter a row in the table? I think that that
is where the problem lies.

[quoted text, click to view]

Query Analyzer.

--
AddThis Social Bookmark Button