Amazon Keyspaces 中的 DML(数据操作语言)语句 - Amazon Keyspaces(针对 Apache Cassandra)
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

Amazon Keyspaces 中的 DML(数据操作语言)语句

数据操作语言 (DML) 是一组用于管理 Amazon Keyspaces (for Apache Cassandra) 表中的数据的 CQL 语句。可以使用 DML 语句在表中添加、修改或删除数据。

还可以使用 DML 语句查询表中的数据。(请注意,CQL 不支持联接或子查询。)

SELECT

使用 SELECT 语句可查询数据。

语法

select_statement ::= SELECT ( select_clause | '*' ) FROM table_name [ WHERE where_clause ] [ LIMIT (integer | bind_marker) ] [ ALLOW FILTERING ] select_clause ::= selector [ AS identifier ] ( ',' selector [ AS identifier ] ) selector ::= column_name | term | CAST '(' selector AS cql_type ')' | function_name '(' [ selector ( ',' selector )* ] ')' where_clause ::= relation ( AND relation )* relation ::= column_name operator term '(' column_name ( ',' column_name )* ')' operator tuple_literal operator ::= '=' | '<' | '>' | '<=' | '>=' | CONTAINS | CONTAINS KEY

示例

SELECT name, id, manager_id FROM "myGSGKeyspace".employees_tbl ;

INSERT

使用 INSERT 语句可向表添加行。

语法

insert_statement ::= INSERT INTO table_name ( names_values ) [ IF NOT EXISTS ] names_values ::= names VALUES tuple_literal names ::= '(' column_name ( ',' column_name )* ')'

示例

INSERT INTO "myGSGKeyspace".employees_tbl (id, name, project, region, division, role, pay_scale, vacation_hrs, manager_id) VALUES ('012-34-5678','Russ','NightFlight','US','Engineering','IC',3,12.5, '234-56-7890') ;

UPDATE

使用 UPDATE 语句可修改表中的行。

语法

update_statement ::= UPDATE table_name [ USING update_parameter ( AND update_parameter )* ] SET assignment ( ',' assignment )* WHERE where_clause [ IF ( EXISTS | condition ( AND condition )*) ] update_parameter ::= ( integer | bind_marker ) assignment ::= simple_selection '=' term | column_name '=' column_name ( '+' | '-' ) term | column_name '=' list_literal '+' column_name simple_selection ::= column_name | column_name '[' term ']' | column_name '.' `field_name condition ::= simple_selection operator term

示例

UPDATE "myGSGKeyspace".employees_tbl SET pay_scale = 5 WHERE id = '567-89-0123' AND division = 'Marketing' ;

要递增 counter,请使用以下语法。有关更多信息,请参阅计数器

UPDATE ActiveUsers SET counter = counter + 1 WHERE user = A70FE1C0-5408-4AE3-BE34-8733E5K09F14 AND action = 'click';

DELETE

使用 DELETE 语句可从表中删除行。

语法

delete_statement ::= DELETE [ simple_selection ( ',' simple_selection ) ] FROM table_name WHERE where_clause [ IF ( EXISTS | condition ( AND condition )*) ] simple_selection ::= column_name | column_name '[' term ']' | column_name '.' `field_name condition ::= simple_selection operator term

其中:

  • table_name 是包含要删除的行的表。

示例

DELETE manager_id FROM "myGSGKeyspace".employees_tbl WHERE id='789-01-2345' AND division='Executive' ;