MS Access CREATE TABLE "WITH COMPRESSION" 语法?

MS Access CREATE TABLE "WITH COMPRESSION" syntax?

我正在尝试为 Microsoft Access 编写 CREATE TABLE 语句(通过使用 OleDbConnection 的 C#/.NET 应用程序执行),利用 WITH COMPRESSION 属性导致字符列( TEXT) 使用单字节字符而不是 Unicode 双字节字符创建,如 MSDN here.

中所述

The WITH COMPRESSION attribute can be used only with the CHARACTER and MEMO (also known as TEXT) data types and their synonyms.

The WITH COMPRESSION attribute was added for CHARACTER columns because of the change to the Unicode character representation format. Unicode characters uniformly require two bytes for each character. For existing Microsoft® Jet databases that contain predominately character data, this could mean that the database file would nearly double in size when converted to the Microsoft Access database engine format. However, Unicode representation of many character sets, those formerly denoted as Single-Byte Character Sets (SBCS) can easily be compressed to a single byte. If you define a CHARACTER column with this attribute, data will automatically be compressed as it is stored and uncompressed when retrieved from the column.

当我尝试通过 OleDbConnection 执行以下语句(根据 MSDN 我认为它在语法上是正确的)时,出现语法错误。

CREATE TABLE [Foo] ([COL1] TEXT(255) WITH COMPRESSION)

同样,直接在 MS Access 2013 中执行相同的语句作为查询会在 WITH.

处出现语法错误

正在执行

CurrentProject.Connection.Execute("CREATE TABLE [Foo1] ([COL1] TEXT(255) WITH COMPRESSION)")
但是,

来自 Access VBA 有效。

如果我去掉 WITH COMPRESSION 属性,语句将通过 OleDb 和直接在 MS Access 中执行而不会出错。

知道我做错了什么吗?

我的问题原来是一个语法错误,在我原来的问题中没有正确反映出来。

但是,解决该问题表明 MSDN https://msdn.microsoft.com/en-us/library/office/ff837200.aspx 上的 MS Access CREATE TABLE 文档在 CREATE TABLE 语句的属性序列方面是不正确的。根据文档,语法是:

CREATE [TEMPORARY] TABLE table (field1 type [(size)] [NOT NULL] [WITH COMPRESSION | WITH COMP] [index1] [, field2 type [(size)] [NOT NULL] [index2] [, …]] [, CONSTRAINT multifieldindex [, …]])

但实际上,[WITH COMPRESSION | WITH COMP] 必须出现在 之前 [NOT NULL] 否则会出现语法错误。

此外,无法直接在 MS Access 中使用 WITH COMPRESSION 属性从查询中执行 CREATE TABLE 语句。您必须使用 VBA 或(在我的情况下)通过 OleDbConnection.

的外部程序

我对 "WITH COMPRESSION" 和 MS-ACCESS 2013 的体验 不可能 运行 查询 window 这样的脚本。 可能来自 VBA,但有限制:

currentdb.Execute "...WITH COMPRESSION" -> "CREATE 中的语法错误 TABLE" CurrentProject.Connection.Execute " ..." -> 好的

我确认 "Mr. T" 所说的:WITH COMPRESSION 必须出现在 之前 NOT NULL