使用事件表

您可以对创建的事件表执行表操作的子集,该表是专门为获取事件而设计的。本主题中的各部分介绍事件表支持的操作。

Note

如本主题所述,您只能在默认事件表上执行此处列出的操作子集。

事件表支持的操作

由于事件表是专门为获取事件而设计的,因此无法对事件表执行可在普通表上执行的某些操作。

使用事件表,您可以执行以下操作(注意默认事件表的例外情况):

OperationDefault event table supportUser-created event table support
SHOW EVENT TABLES
DESCRIBE EVENT TABLE
SELECT
DROP TABLE
UNDROP TABLE
CREATE TABLE
TRUNCATE TABLE
DELETE
ALTER TABLE (event tables)✔ (rename is not supported)✔ (rename is not supported)

从事件表中删除行

如果需要从事件表中删除行,可以使用以下命令:

  • Use TRUNCATE TABLE to remove all rows from the event table.
  • Use DELETE to remove selected rows from the event table.

如果需要实施更复杂的日志保留策略(例如,某些函数的日志保留时间需要比其他函数长),则可以使用此命令。

事件表的参数

您可以使用以下参数指定处理程序代码应如何使用事件表。

EVENT_TABLE

Specifies the name of the event table for logging messages from stored procedures and UDFs in this account. For reference information, see EVENT_TABLE.

LOG_LEVEL

Specifies the severity level of log messages produced through logging APIs that should be ingested and made available in the active event table. Log messages at the specified level (and at more severe levels) are ingested. For more information, see LOG_LEVEL and Setting levels for logging, metrics, and tracing.

LOG_EVENT_LEVEL

Specifies the severity level of log events (rows with record type EVENT) that should be ingested and made available in the active event table. Log events at the specified level (and at more severe levels) are ingested. For more information, see LOG_EVENT_LEVEL and Setting levels for logging, metrics, and tracing.

METRIC_LEVEL

Specifies whether metrics data should be ingested and made available in the active event table. For more information, see METRIC_LEVEL and Setting levels for logging, metrics, and tracing.

TRACE_LEVEL

Specifies the verbosity of trace events that should be ingested and made available in the active event table. Events at the specified level are ingested. For more information, see TRACE_LEVEL and Setting levels for logging, metrics, and tracing.

事件表的访问控制权限

您可以使用全局和事件表范围的权限来管理对事件表操作的访问。

For more information, see Event table privileges and log level privileges in Global privileges (account privileges).

管理对事件表数据的访问

如果无法将事件表数据提供给一系列用户和角色,则可以创建视图供具有特定角色的用户访问。

如果要管理对此表中数据的访问,可以在事件表上创建视图,然后将每个视图的访问权限授予不同的角色。通过视图,角色可能有权访问事件表中指定的数据子集。

For more information about creating views, see CREATE VIEW.

使用流来跟踪对事件表的更改

您可以在事件表上创建流,例如获取表的变更。

For more information about streams, see Introduction to streams and CREATE STREAM.

Code in the following example creates a stream to capture inserts on the event table my_event_table.

CREATE STREAM append_only_comparison ON EVENT TABLE my_event_table APPEND_ONLY=TRUE;