Saturday, February 25, 2012

Default Values in SQL Server

I am designing a new Database using SQL Server 2000 Enterprise Manager. I have a field called Phone, Fax and Zip.

Under Enterprise Manager I am trying to set up default values for these fields

Phone, Fax = 000-000-000
Zip = 00000

However Sql Server truncates it to 0.

How do I default value as shown about in SQL server?You must have the column set to int?

Change it to varchar(30) and you should be fine.

ScAndal|||I have Phone, Fax nvarchar(12) and Zip as nvarchar(5)

I don't know why this doesn't work !!|||Ok.. I got the solution

For default value instead of putting 000-000-000 with nvarchar(12) I put '000-000-0000' and it works fine.

1) How do I use 'Formula' field in Enterprise Manager works?
2) How do I work with various Timezone issue ?|||love,
How did you determine it is storing as 0? Did you select the data from query analyzer and it shows 0?

ScAndal|||I right clicked on table and selected 'Return All Rows' where I saw 0 instead of 00000

Another way was, once I put value in Default field as 00000 and save table, return to the same column it will indiate data as (0) for zip and (0-0-0) for phone and fax.

This and your data type indicated me that there is something wrong with my default value.

No comments:

Post a Comment