SQL Server 数据类型映射

SQL Server 和 .NET Framework 基于不同的类型系统。 例如,.NET Framework Decimal 结构的最大小数位数为 28,而 SQL Server 的 decimal 和 numeric 数据类型的最大小数位数为 38。 为了在读取和写入数据时维护数据的完整性,SqlDataReader 将公开用于返回 System.Data.SqlTypes 的对象的 SQL Server 特定的类型化访问器方法以及用于返回 .NET Framework 类型的访问器方法。 SQL Server 类型和 .NET Framework 类型也可通过 DbType 和 SqlDbType 类中的枚举表示,当您指定 SqlParameter 数据类型时可以使用这些枚举。

下表显示推断的 .NET Framework 类型、DbType 和 SqlDbType 枚举以及 SqlDataReader 的访问器方法。

SQL Server 数据库引擎类型 .NET Framework 类型 SqlDbType 枚举 SqlDataReader SqlTypes 类型化访问器 DbType 枚举 SqlDataReader DbType 类型化访问器
bigint Int64 BigInt GetSqlInt64 Int64 GetInt64
binary Byte[] VarBinary GetSqlBinary Binary GetBytes
bit Boolean Bit GetSqlBoolean Boolean GetBoolean
char String

Char[]
Char GetSqlString AnsiStringFixedLength,

String
GetString

GetChars
日期1

(SQL Server 2008 及更高版本)
DateTime Date 1 GetSqlDateTime Date 1 GetDateTime
datetime DateTime DateTime GetSqlDateTime DateTime GetDateTime
datetime2

(SQL Server 2008 及更高版本)
DateTime DateTime2 DateTime2 GetDateTime
datetimeoffset

(SQL Server 2008 及更高版本)
DateTimeOffset DateTimeOffset DateTimeOffset GetDateTimeOffset
decimal Decimal Decimal GetSqlDecimal Decimal GetDecimal
FILESTREAM 特性 (varbinary(max)) Byte[] VarBinary GetSqlBytes Binary GetBytes
float Double Float GetSqlDouble Double GetDouble
图像 Byte[] Binary GetSqlBinary Binary GetBytes
int Int32 Int GetSqlInt32 Int32 GetInt32
money Decimal Money GetSqlMoney Decimal GetDecimal
nchar String

Char[]
NChar GetSqlString StringFixedLength GetString

GetChars
ntext String

Char[]
NText GetSqlString String GetString

GetChars
数值 Decimal Decimal GetSqlDecimal Decimal GetDecimal
nvarchar String

Char[]
NVarChar GetSqlString String GetString

GetChars
实数 Single Real GetSqlSingle Single GetFloat
rowversion Byte[] Timestamp GetSqlBinary Binary GetBytes
smalldatetime DateTime DateTime GetSqlDateTime DateTime GetDateTime
smallint Int16 SmallInt GetSqlInt16 Int16 GetInt16
smallmoney Decimal SmallMoney GetSqlMoney Decimal GetDecimal
sql_variant 对象2 Variant GetSqlValue 2 Object GetValue 2
文本 String

Char[]
Text GetSqlString String GetString

GetChars
时间

(SQL Server 2008 及更高版本)
TimeSpan Time Time GetDateTime
时间戳 Byte[] Timestamp GetSqlBinary Binary GetBytes
tinyint Byte TinyInt GetSqlByte Byte GetByte
uniqueidentifier Guid UniqueIdentifier GetSqlGuid Guid GetGuid
varbinary Byte[] VarBinary GetSqlBinary Binary GetBytes
varchar String

Char[]
VarChar GetSqlString AnsiStringString GetString

GetChars
xml Xml Xml GetSqlXml Xml

1无法设置DbType属性SqlParameterSqlDbType.Date
2使用特定的类型化访问器,如果你知道的基础类型sql_variant

来源https://docs.microsoft.com/zh-cn/dotnet/framework/data/adonet/sql-server-data-type-mappings


转自:
SQL Server 数据类型映射(转载) - hao_1234_1234 - 博客园
https://www.cnblogs.com/hao-1234-1234/p/8870838.html

(转)SQL Server 数据类型映射的更多相关文章

  1. SQL Server 数据类型映射 (ADO.NET)

    SQL Server 数据类型映射 (ADO.NET) .NET Framework 3.5 更新:November 2007 SQL Server 和 .NET Framework 基于不同的类型系 ...

  2. SQL Server 数据类型映射(转载)

    SQL Server 数据类型映射 SQL Server 和 .NET Framework 基于不同的类型系统. 例如,.NET Framework Decimal 结构的最大小数位数为 28,而 S ...

  3. SQL Server 数据类型映射

    SQL Server 和 .NET Framework 基于不同的类型系统. 例如,.NET Framework Decimal 结构的最大小数位数为 28,而 SQL Server 的 decima ...

  4. 为更好地设计数据库,重新整理sql server数据类型

    我们在平常开发过程中,在设计数据的时候,经常碰到数据类型选择的问题,为了更快,更合适地选择正确的数据类型,所以在这里做个总结. 分类 sql server 数据类型 c# 数据类型 描述 应用场景 字 ...

  5. MySql和SQL Server数据类型 对比

    My Sql 数据类型 SQL Server 数据类型 Yes/No bit Smallint(字节型) tinyint Integer(长整型) int Real(单精度浮点型)    real F ...

  6. SQL Server数据类型与SDE库表sde_type对照表

    SDE_column_registry 表管理所有注册列. 警告:如果使用 SQL 界面更改列定义,SDE_column_registry 表中的记录将不会更新.这可能导致之后的任何数据导出失败. S ...

  7. SQL Server数据类型

    转载:http://www.ezloo.com/2008/10/sql_server_data_type.html    数据类型是数据的一种属性,是数据所表示信息的类型.任何一种语言都有它自己所固有 ...

  8. SQL Server 数据类型 Decimal介绍

    为SQL Server 数据类型,属于浮点数类型.存储数据范围是: -1038~1038-1 的固定精度和小数位的数字.一个decimal类型的数据占用了2~17个字节.decimal数据类型在SQL ...

  9. SQL Server数据类型int、bigint、smallint、tinyint对比表

    SQL Server数据类型int.bigint.smallint.tinyint对比表 数据类型 范围 存储 bigint -2^63 (-9,223,372,036,854,775,808) 到 ...

随机推荐

  1. python包导入

    https://www.cnblogs.com/foremostxl/p/9501663.html

  2. Openstack API 类型 & REST 风格

    目录 目录 Openstack 提供了三种操作方式 Web界面 CIL 指令行 RESTful API REST 风格 RESTFul风格的API设计 基于HTTP协议的RESTful API Ope ...

  3. Ubuntu解压缩rar格式文件

    解压缩rar文件时,出现问题 解决方法: sudo apt-get install unrar

  4. Springboot02-配置文件

    配置文件读取 springboot中的配置文件都放在application.properties中,其中而k-v属性可以通过@Value("${属性名}")直接获取 @Compon ...

  5. 选择器与过滤器(全)————JQ

    JQ基础--选择器与过滤器(全) JQ选择器 <!DOCTYPE html> <html> <head> <meta charset="UTF-8& ...

  6. send csv to es with filebeat

    ## filebeat *.csv 2019-11-30 23:27:50,111111,222222,VIEW,333333333333 filebeat filebeat.inputs:- pat ...

  7. css3--文字效果

    text-shadow <!DOCTYPE html> <html> <head> <meta charset="utf-8"> & ...

  8. 基于window ftp上传问题

    FtpClient上传文件异常:java.net.SocketException: Connection reset cmd输入: netsh advfirewall set global State ...

  9. Windows下Maven安装 + eclipse集成

    一.什么是maven? Maven是一个项目管理工具,能方便的帮我们下载jar包,告别传统手动导包的方式. 二.maven仓库 maven中有中央仓库,本地仓库,私服三个概念 1.中央仓库是maven ...

  10. sparksql笔记

    1.sparksql是Spark用来处理结构化数据的一个模块,它提供了两个抽象DataFrame和DataSet并且作为分布式SQL查询引擎的作用. Hive SQL转换成MapReduce然后提交到 ...