您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.
了解表服务数据模型Understanding the Table service data model
表服务提供表形式的结构化存储。The Table service offers structured storage in the form of tables. 以下各节概述表服务数据模型。The following sections outline the Table service data model.
存储帐户Storage Account
存储帐户是在存储系统中全局唯一的实体。A storage account is a globally unique entity within the storage system. 存储帐户是表服务的父命名空间,是授权的基础。The storage account is the parent namespace for the Table service, and is the basis for authorization. 只要每个表的名称都独一无二,即可在给定的存储帐户中创建任意数量的表。You can create any number of tables within a given storage account, as long as each table is uniquely named.
必须始终在请求 URI 中指定存储帐户。The storage account must always be specified in the request URI. 用于访问表服务的基 URI 如下所示:The base URI for accessing the Table service is as follows:
https://myaccount.table.core.windows.net
表、实体和属性Tables, Entities, and Properties
表以实体集合的形式存储数据。Tables store data as collections of entities. 实体与行类似。Entities are similar to rows. 一个实体具有一个主键和一组属性。An entity has a primary key and a set of properties. 属性与列类似,是一个名称/类型化值对。A property is a name, typed-value pair, similar to a column.
表服务不对表施加任何架构,因此同一表中的两个实体可具有两组不同的属性。The Table service does not enforce any schema for tables, so two entities in the same table may have different sets of properties. 开发人员可在客户端一侧施加架构。Developers may choose to enforce a schema on the client side. 一个表可以包含任意数量的实体。A table may contain any number of entities.
表名称Table Names
表名必须遵循以下规则:Table names must conform to these rules:
表名必须在帐户中独一无二。Table names must be unique within an account.
表名只能包含字母数字字符。Table names may contain only alphanumeric characters.
表名不能以数字字符开头。Table names cannot begin with a numeric character.
表名不区分大小写。Table names are case-insensitive.
表名的长度必须为 3 到 63 个字符。Table names must be from 3 to 63 characters long.
某些表名是保留的名称,包括“tables”。Some table names are reserved, including "tables". 尝试创建具有保留表名的表将返回错误代码 404(错误请求)。Attempting to create a table with a reserved table name returns error code 404 (Bad Request).
正则表达式 "^ [A Za-z] [a-za-z0-9] $" 也描述了这些规则 {2,62} 。These rules are also described by the regular expression "^[A-Za-z][A-Za-z0-9]{2,62}$".
表名保留创建时的大小写,但使用表名时不区分大小写。Table names preserve the case with which they were created, but are case-insensitive when used.
属性名称Property Names
属性名称是长度最大为 255 个字符、区分大小写的字符串。Property names are case-sensitive strings up to 255 characters in size. 属性名称应遵循 c # 标识符的命名规则。Property names should follow naming rules for C# identifiers.
备注
根据 XML 规范,某些 c # 标识符是无效的。Some C# identifiers are not valid according to the XML specification. 属性名称中不能使用这些标识符,因为在对表服务的请求中,这些属性名称需要通过 XML 负载发送。These identifiers may not be used in property names, because property names are sent via an XML payload in a request against the Table service.
重要
属性名称在 URL 中传递给表服务。Property names are passed to the Table service within a URL. 某些字符必须使用 UTF-8(首选)或 MBCS 以百分比编码形式出现在 URL 中。Certain characters must be percent-encoded to appear in a URL, using UTF-8 (preferred) or MBCS. 当你使用 Azure 存储客户端库时,将自动进行此编码。This encoding occurs automatically when you use the Azure Storage client libraries. 但是,即使经过编码,还是有一些字符在 URL 路径中无效。However, there are certain characters that are not valid in URL paths even when encoded. 这些字符不能出现在属性名称中。These characters cannot appear in property names. 像 \uE000 这样的码位虽然在 NTFS 文件名中有效,但不是有效的 Unicode 字符,因此无法使用。Code points like \uE000, while valid in NTFS filenames, are not valid Unicode characters, so they cannot be used. 此外,也不允许使用某些 ASCII 或 Unicode 字符,如控制字符(0x00 到 0x1F、\u0081 等)。In addition, some ASCII or Unicode characters, like control characters (0x00 to 0x1F, \u0081, etc.), are also not allowed. 有关管理 HTTP/1.1 中的 Unicode 字符串的规则,请参见:For rules governing Unicode strings in HTTP/1.1 see:
备注
自 2009-04-14 版开始,表服务不再支持属性名称中包括短划线 (-) 字符。Beginning with version 2009-04-14, the Table service no longer supports including the dash (-) character in property names.
属性限制Property Limitations
一个实体最多可具有 255 个属性,包括下一节中描述的 3 个系统属性。An entity can have up to 255 properties, including 3 system properties described in the following section. 因此,除了这 3 个系统属性之外,用户最多还可加入 252 个自定义属性。Therefore, the user may include up to 252 custom properties, in addition to the 3 system properties. 实体属性中所有数据的总大小不能超过 1 MiB。The combined size of all data in an entity's properties cannot exceed 1 MiB.
系统属性System Properties
实体始终具有以下系统属性:An entity always has the following system properties:
PartitionKey
属性PartitionKey
propertyRowKey
属性RowKey
propertyTimestamp
属性Timestamp
property
表中的每个实体会自动包括上述系统属性。These system properties are automatically included for every entity in a table. 这些属性的名称是保留的名称,因此无法更改。The names of these properties are reserved and cannot be changed. 开发人员负责插入并更新 PartitionKey
和 RowKey
的值。The developer is responsible for inserting and updating the values of PartitionKey
and RowKey
. 服务器管理 Timestamp
的值,无法修改该值。The server manages the value of Timestamp
, which cannot be modified.
键字段中禁用的字符Characters Disallowed in Key Fields
PartitionKey
和 RowKey
属性的值中不允许使用下列字符:The following characters are not allowed in values for the PartitionKey
and RowKey
properties:
正斜杠 (/) 字符The forward slash (/) character
反斜杠 (\) 字符The backslash (\) character
数字记号 (#) 字符The number sign (#) character
问号 (?) 字符The question mark (?) character
从 U+0000 到 U+001F 的控制字符,包括:Control characters from U+0000 to U+001F, including:
- 水平制表符 (\t) 字符The horizontal tab (\t) character
- 换行符 (\n) 字符The linefeed (\n) character
- 回车 (\r) 字符The carriage return (\r) character
从 U+007F 到 U+009F 的控制字符Control characters from U+007F to U+009F
PartitionKey 属性PartitionKey Property
将对表进行分区以支持跨存储节点的负载平衡。Tables are partitioned to support load balancing across storage nodes. 表的实体按分区加以组织。A table's entities are organized by partition. 分区是拥有相同分区键值的一系列连续实体。A partition is a consecutive range of entities possessing the same partition key value. 分区键是给定表中的分区的唯一标识符,由 PartitionKey
属性指定。The partition key is a unique identifier for the partition within a given table, specified by the PartitionKey
property. 分区键构成了实体的主键的第一部分。The partition key forms the first part of an entity's primary key. 分区键的大小可以是最大为 1 KiB 的字符串值。The partition key may be a string value up to 1 KiB in size.
必须在每个插入、更新和删除操作中加入 PartitionKey
属性。You must include the PartitionKey
property in every insert, update, and delete operation.
RowKey 属性RowKey Property
主键的第二部分是行键,由 RowKey
属性指定。The second part of the primary key is the row key, specified by the RowKey
property. 行键是某个给定分区中实体的唯一标识符。The row key is a unique identifier for an entity within a given partition. PartitionKey
和 RowKey
共同唯一标识表中的每个实体。Together the PartitionKey
and RowKey
uniquely identify every entity within a table.
行键是一个字符串值,其大小最大可为 1 KiB。The row key is a string value that may be up to 1 KiB in size.
必须在每个插入、更新和删除操作中加入 RowKey
属性。You must include the RowKey
property in every insert, update, and delete operation.
Timestamp 属性Timestamp Property
Timestamp
属性是一个 DateTime
值,该值保留在服务器端以记录上次修改实体的时间。The Timestamp
property is a DateTime
value that is maintained on the server side to record the time an entity was last modified. 表服务在内部使用 Timestamp
属性以提供乐观并发。The Table service uses the Timestamp
property internally to provide optimistic concurrency. Timestamp
每次修改实体时,实体的属性值都会增加。The value of the Timestamp
property for an entity advances each time the entity is modified. 不应在插入或更新操作中设置此属性(将忽略其值)。This property should not be set on insert or update operations (the value will be ignored).
Timestamp
属性必须以接受的 ISO 8601 UTC 格式之一来表示。The Timestamp
property must be expressed in one of the accepted ISO 8601 UTC formats. 有关接受的 UTC 格式的详细信息,请参阅 设置日期时间值的格式。For more information about accepted UTC formats, see Formatting DateTime values.
属性类型Property Types
表服务支持由 OData 协议规范定义的数据类型的子集。The Table service supports a subset of data types defined by the OData Protocol Specification. 下表显示了表服务支持的属性类型:The following table shows the supported property types for the Table service:
Odata 数据类型OData Data Type | 公共语言运行时类型Common Language Runtime type | 详细信息Details |
---|---|---|
Edm.Binary |
byte[] |
字节数组,最大为 64 KiB。An array of bytes up to 64 KiB in size. |
Edm.Boolean |
bool |
一个布尔值。A Boolean value. |
Edm.DateTime |
DateTime |
一个 64 位值,用协调世界时 (UTC) 表示。A 64-bit value expressed as Coordinated Universal Time (UTC). 支持的 DateTime 范围从公元 1601 年 1 月 1 日午夜 12:00 The supported DateTime range begins from 12:00 midnight, January 1, 1601 A.D. 午夜 12:00 开始。(C.E.), UTC. 到 9999 年 12 月 31 日结束。The range ends at December 31, 9999. 有关详细信息,请参阅 设置日期时间值的格式。For more information, see Formatting DateTime values. |
Edm.Double |
double |
64 位浮点值。A 64-bit floating point value. |
Edm.Guid |
Guid |
128 位全局唯一标识符。A 128-bit globally unique identifier. |
Edm.Int32 |
Int32 或 int Int32 or int |
32 位整数。A 32-bit integer. |
Edm.Int64 |
Int64 或 long Int64 or long |
64 位整数。A 64-bit integer. |
Edm.String |
String |
UTF-16 编码值。A UTF-16-encoded value. 字符串值最大可以为 64 KiB。String values may be up to 64 KiB in size. 请注意,支持的最大字符数约为 32 K 或更小。Note that the maximum number of characters supported is about 32 K or less. |
默认情况下,除非指定其他类型,否则以 String
类型创建属性。By default a property is created as type String
, unless you specify a different type. 若要显式键入属性,请使用 插入实体 或 更新实体 操作的相应 OData 数据类型指定其数据类型。To explicitly type a property, specify its data type by using the appropriate OData data type for an Insert Entity or Update Entity operation. 有关详细信息,请参阅 插入和更新实体。For more information, see Inserting and Updating Entities.
表服务不保留 null
属性值。The Table service does not persist null
values for properties. 查询实体时,上述属性类型都是不可为 null 的。When querying entities, the above property types are all non-nullable. 写入实体时,上述属性类型都是可以为 null 的,并处理任何具有值的属性, null
就像负载不包含该属性一样。When writing entities, the above property types are all nullable, and any property with a null
value is handled as if the payload did not contain that property.
有关演示如何筛选查询请求 URI 中各种属性类型的示例,请参阅 查询表和实体。For examples that show how to filter on the various property types in a query request URI, see Querying Tables and Entities.