blog.jj5.net (2003 to 2005)

SQL Server Types and .NET System.Data.SqlTypes

Mon Mar 15 14:46:00 UTC+1100 2004

Categories:

Well, I put this off long enough. Here is a reference for SQL Server => .NET type conversions.

I think I got it right. I'm not sure if there are any little gotchas that I'm not aware of yet..

John.

SQL Server Mono SqlTypes Notes
BINARY => SqlBinary Tax 4B. Cap 1B to 8,000B.
BIGINT => SqlInt64 Sto 8B. Rng -2^63 to 2^63 - 1.
BIT => SqlBoolean Sto 8 fields per 1B. Rng 0 and 1.
CHAR => SqlString Cap 1 to 8,000 char.
DATETIME => SqlDateTime Sto 8B. Rng 1753-01-01 to 9999-12-31. Acc ~0.003 secs.
DECIMAL => SqlDecimal Precision. Scale. Sto. Max Rng - 10^38 + 1 to 10^38 - 1
FLOAT => SqlDouble Mantissa. Sto.
IMAGE => SqlBinary Variable-length binary data. Tax 16B. Cap 0B to 2^31 - 1B.
INT => SqlInt32 Sto 4B. Rng -2^31 to 2^31 - 1.
MONEY => SqlMoney Sto 8B. Rng -2^63 to 2^63 - 1. Acc to 0.0001.
NCHAR => SqlString Cap 1 to 4000 nchar.
NTEXT => SqlString Tax 16B. Cap 0 to 2^30 - 1 nchar.
NVARCHAR => SqlString Cap 1 (allows 0) to 4,000 nchar.
NUMERIC => SqlDecimal Fixed Precision and Scale. Same as DECIMAL.
REAL => SqlSingle REAL is FLOAT(24). Sto 4B.
SMALLDATETIME => SqlDateTime Sto 4B. Rng 1900-01-01 to 2079-06-06. Acc 1 minutes.
SMALLINT => SqlInt16 Sto 2B. Rng -2^15 to 2^15 - 1.
SMALLMONEY => SqlMoney Sto 4B. Rng -2^31 to 2^31 - 1. Acc to 0.0001.
SQL_VARIANT => varies Models various types in a single column. See usage.
TEXT => SqlString Tax 16B. Cap 0 to 2^31 - 1 char.
TIMESTAMP => SqlBinary(8) Sto 8B. Used as ROWVERSION. Only one per table.
TINYINT => SqlByte Sto 1B. Rng 0 to 255.
VARBINARY => SqlBinary Tax 4B. Cap 1B (allows 0) to 8,000B.
VARCHAR => SqlString Cap 1 (allows 0) to 8,000 char.
UNIQUEIDENTIFIER => SqlGuid Sto 16B. Use NEWID() to create.

Copyright © 2003-2005 John Elliot