本文记录各种数据库与.NET类型的对照,包括Oracle,SQL Server,MySQL,SQLite
首先是Oracle的
序号 | Oracle数据类型 | .NET类型 |
1 | BFILE | byte[] |
2 | BLOB | byte[] |
3 | CHAR | string |
4 | CLOB | string |
5 | DATE | DateTime |
6 | FLOAT | Decimal |
7 | INTEGER | Decimal |
8 | INTERVAL YEAR TO MONTH | Int32 |
9 | INTERVAL DAY TO SECOND | TimeSpan |
10 | LONG | string |
11 | LONG RAW | byte[] |
12 | NCHAR | string |
13 | NCLOB | string |
14 | NUMBER | Decimal |
15 | NVARCHAR2 | string |
16 | RAW | byte[] |
17 | ROWID | string |
18 | TIMESTAMP | DateTime |
19 | VARCHAR2 | string |
接着到SQL Server,这个是从MSDN搞来的
序号 | SQL Server 数据类型 | .NET 类型 |
1 | bigint | Int64 |
2 | binary | Byte[] |
3 | bit | Boolean |
4 | char | String |
Char[] | ||
5 | date | DateTime |
(仅适用 SQL Server 2008) | ||
6 | datetime | DateTime |
7 | datetime2 | DateTime2 |
(仅适用 SQL Server 2008) | ||
8 | datetimeoffset | DateTimeOffset |
(仅适用 SQL Server 2008) | ||
9 | decimal | Decimal |
10 | FILESTREAM 属性 (varbinary(max) | Byte[] |
11 | float | Double |
image | Byte[] | |
12 | int | Int32 |
13 | money | Decimal |
14 | nchar | String |
Char[] | ||
15 | ntext | String |
Char[] | ||
16 | numeric | Decimal |
17 | nvarchar | String |
Char[] | ||
18 | real | Single |
19 | rowversion | Byte[] |
20 | smalldatetime | DateTime |
21 | smallint | Int16 |
22 | smallmoney | Decimal |
23 | sql_variant | Object* |
24 | text | String |
Char[] | ||
25 | time | TimeSpan |
(仅适用 SQL Server 2008) | ||
26 | timestamp | Byte[] |
27 | tinyint | Byte |
28 | uniqueidentifier | Guid |
29 | varbinary | Byte[] |
30 | varchar | String |
Char[] | ||
31 | xml | Xml |
到MySQL,这个可能不太准,我是从MySQL与Java类型对照转过来的
序号 | MySQL数据类型 | .NET类型 |
1 | VARCHAR | String |
2 | CHAR | string |
3 | BLOB | byte |
4 | TEXT | string |
5 | INTEGER | Int64 |
6 | TINYINT | Int32 |
7 | SMALLINT | Int33 |
8 | MEDIUMINT | Int34 |
9 | BIT | Boolean |
10 | BIGINT | Int64 |
11 | FLOAT | Single |
12 | DOUBLE | Double |
13 | DECIMAL | Decimal |
14 | BOOLEAN | Int32 |
15 | ID | Int64 |
16 | DATE | DateTime |
17 | TIME | DateTime |
18 | DATETIME | DateTime |
19 | TIMESTAMP | DateTime |
20 | YEAR | DateTime |
21 | ENUM | string |
最后到SQLite的,其实SQLite只有5种数据类型,下表列了那么多都是为了兼容其他数据库弄出来的,存到SQLite里头就只有5种而已,但还是区分一下比较好,免得读数据时因为数据过大而出错。
序号 | SQLite 数据类型 | .NET 类型 | 亲缘类型 |
1 | INT | int32 | INTEGER |
2 | INTEGER | int64 | |
3 | TINYINT | int16 | |
4 | SMALLINT | int16 | |
5 | MEDIUMINT | int32 | |
6 | BIGINT | int64 | |
7 | UNSIGNED BIG INT | int64 | |
8 | INT2 | int16 | |
9 | INT8 | int64 | |
10 | CHARACTER | string | TEXT |
11 | VARCHAR | string | |
12 | VARYING CHARACTER | string | |
13 | NCHAR | string | |
14 | NATIVE CHARACTER | string | |
15 | NVARCHAR | string | |
16 | TEXT | string | |
17 | CLOB | string | |
18 | BLOB | byte[] | BLOB |
19 | REAL | double | REAL |
20 | DOUBLE | double | |
21 | DOUBLE PRECISION | double | |
22 | FLOAT | single | |
23 | NUMERIC | Decimal | NUMERIC |
24 | DECIMAL | Decimal | |
25 | BOOLEAN | byte | |
26 | DATE | datetime | |
27 | DATETIME | datetime |