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
 General SQL Server Forums
 New to SQL Server Programming
 Creating new field with default values...

Author  Topic 

Topaz
Posting Yak Master

199 Posts

Posted - 2007-11-07 : 07:21:08
I am creating a new filed in SQL Server 2005, and I want the field to have the default of '0'

I select the data type as numeric and save my changes, I then visit our front end database to see if the default value is just '0' but it appears as '0.00'

SO i thought about changing the default value to int (im thinking this means integer?) and changing it to '3' but it still displays the decimal point and two 0's

Am I doing something wrong here? I just want it to display '0'

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-07 : 07:26:29
Drop or delete the column. Save.
Add the column and use INT as datatype and 0 as default.
Save.


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Topaz
Posting Yak Master

199 Posts

Posted - 2007-11-07 : 07:33:20
ok. thats what we thought would work, but now it doesn't even display any value i.e its blank.

Im using wired contact will this make any difference you think?
Go to Top of Page

KenW
Constraint Violating Yak Guru

391 Posts

Posted - 2007-11-07 : 13:49:16
No, your problem is that a column in SQL Server isn't automatically set to a value when a row is added; instead, it's set to NULL. NULL isn't usually displayed.

When you create your int column definition, add a DEFAULT 0 clause at the end. For more info, see CREATE TABLE or ALTER COLUMN in BOL.
Go to Top of Page

Topaz
Posting Yak Master

199 Posts

Posted - 2007-11-08 : 09:55:43
What is BOL?
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2007-11-08 : 09:56:34
Books online (helpfile that comes with sql server)


Em
Go to Top of Page

Topaz
Posting Yak Master

199 Posts

Posted - 2007-11-08 : 10:02:10
Got it books online...
Go to Top of Page

Topaz
Posting Yak Master

199 Posts

Posted - 2007-11-08 : 10:20:41
Ive had a look at BOL and searched for create table and alter column, but i dont know how to go about editing the columns. The only way ive been able to create colums is by doing this (see screenshot)

[URL=http://allyoucanupload.webshots.com/v/2000051859726397251][/URL]

Is this right?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-08 : 10:26:57
yes


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Topaz
Posting Yak Master

199 Posts

Posted - 2007-11-08 : 10:29:20
I knew it was...

Any thoughts on why its still displaying 0.00? Ive been messing about with this all day! ARGH
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-08 : 10:31:02
try select * from that table in SSMS


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-08 : 10:31:13
Because the column is still numeric, not int.

If you drop the column, SAVE and then add the column again with 0 as default value AND set NOT NULL as an option, yuo will get zero's in all records. Don't forget to save.




E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Topaz
Posting Yak Master

199 Posts

Posted - 2007-11-08 : 10:44:02
ok done that the default now looks like ((0)) I didnt put in the brackets.

Not even showing anything anymore...
Go to Top of Page
   

- Advertisement -