tags:

views:

39

answers:

1

in the sql server database i have a field that is type "numeric". Precision is set to 18 in the database.

when i create a linq to sql class it comes up as this:

 [Column(Storage="_zip", DbType="Decimal(18,0)")]
 public System.Nullable<decimal> zip
 {

Questions are:

  1. do you know why it would choose to my it Decimal. this is obviously not the way i want to store and view zip codes.
  2. what is the best format to store zip codes in my sql server database?

any suggestions?

+2  A: 

This is exactly what it should be. "Numeric" and "Decimal" are identical* in SQL Server - the SQL-92 standard states that they should be functionally identical (this is because before SQL-92 different vendors used different names for the same thing. Supporting all the names preserves backwards compatiblity). .NET only has a decimal type (since it is not SQL it does not need to support a numeric alias, though you could create one).

As for ZIP codes, Numeric(18,0) doesn't sound very good. It's far too large and CPU intensive for regular 5 digit zip codes (Numeric/Decimal is stored as base 10 and requires more processing power), and it doesn't properly store longer ZIP+4 codes which have a dash.

Since ZIP codes are addresses that only happen to be numbers (most of the time, for now), I would suggest you use a varchar(10) field, which will correctly store all ZIP codes, including ZIP+4 (5 digit ZIP code plus dash plus 4 digit extension code).

David
if i change the field to varchar(10), i get an error in SQL server enterprise manager saying that the table will have to be dropped and recreated. you have either made changes to a table that can't be recreated or enable the option to prevent saving changes that require a table recreation
ooo