暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

AntDB数据库用户手册之增删改查——更新表中的数据/查看表中的数据

803

更新表中的数据

update用于更新表中的数据,帮助信息如下:

antdb=#  \h update
Command:     UPDATE
Description: update rows of a table
Syntax:
[ WITH [ RECURSIVE ] with_query [, ...] ]
UPDATE [ ONLY ] table_name [ * ] [ [ AS ] alias ]
    SET { column_name = { expression | DEFAULT } |
          ( column_name [, ...] ) = [ ROW ] ( { expression | DEFAULT } [, ...] ) |
          ( column_name [, ...] ) = ( sub-SELECT )
        } [, ...]
    [ FROM from_list ]
    [ WHERE condition | WHERE CURRENT OF cursor_name ]
    [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

update与delete语句一样,可以通过条件控制来更新单条数据和多条数据。

注意:

  • 尽量避免在生产环境对全表进行update操作。
  • 如果update的数据量比较大,可以考虑使用新建表的形式将数据的新值放入新表,未更新的数据也放入新表中,然后删除旧表,重命名新表。

查看表中的数据

select 语句的用法比较丰富,配合AntDB中的函数、表关联、group by、order by等关键字,高效完成用户的查询需求。

常用select语句:

  • select * from t;
  • select t1.col1,t1.col2 from t t1;
  • select t1.col1,t1.col2 from t t1 where t1.col1 < 10
  • select t1.col1,t2.col2 from a t1, b t2 where t1.id=t2.id;
  • select t1.col1,count(*) from a t1group by t1.col1;
  • select t1.col1,count(*) from a t1group by t1.col1 order by 2;
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论