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

openGauss每日一练第1天 课程笔记和作业

数据库环境

openGauss:2.0.0 - 数据库实训平台

学习目标

学习openGauss数据库创建表、插入记录、查询记录和删除表基本使用

学习笔记

  • 注意DISTINCT虽然去掉了重复数据,但是输出结果的顺序发生了改变。
omm=# select c_first_name from customer_t; c_first_name -------------- Grace Grace Joes Lily James Lucy (6 rows) omm=# SELECT DISTINCT(c_first_name) from customer_t; c_first_name -------------- James Grace Lucy Joes Lily (5 rows)
复制
  • 初次启动时,要等待几秒钟,让环境完成启动。
root@modb:~# root@modb:~# root@modb:~# su - omm omm@modb:~$ gsql -r failed to connect Unknown:5432. omm@modb:~$ gsql -r gsql ((openGauss 2.0.0 build 78689da9) compiled at 2021-03-31 21:03:52 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. omm=#
复制

课后作业

1.创建一个表products

omm=# create table products( omm(# product_id integer, omm(# product_name char(30), omm(# category char(20)); CREATE TABLE omm=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+-------+----------+-------------+-------------+------------------- omm | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/omm + | | | | | omm=CTc/omm template1 | omm | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/omm + | | | | | omm=CTc/omm (4 rows) omm=# \d List of relations Schema | Name | Type | Owner | Storage --------+----------+-------+-------+---------------------------------- public | products | table | omm | {orientation=row,compression=no} (1 row) omm-# \d products Table "public.products" Column | Type | Modifiers --------------+---------------+----------- product_id | integer | product_name | character(30) | category | character(20) |
复制

2.向表中插入数据,采用一次插入一条和多条记录的方式

omm=# insert into products(product_id,product_name,category) values(1502,'olympus camera','electrncs'); INSERT 0 1 omm=# select * from products; product_id | product_name | category ------------+--------------------------------+---------------------- 1502 | olympus camera | electrncs (1 row) insert into products(product_id,product_name,category) values(1601,'lamaze','toys'), (1700,'wait interface','Books'), (1666,'harry potter','toys'); omm=# select * from products; product_id | product_name | category ------------+--------------------------------+---------------------- 1502 | olympus camera | electrncs 1601 | lamaze | toys 1700 | wait interface | Books 1666 | harry potter | toys (4 rows)
复制

3.查询表中所有记录及记录数

omm=# select * from products; product_id | product_name | category ------------+--------------------------------+---------------------- 1502 | olympus camera | electrncs 1601 | lamaze | toys 1700 | wait interface | Books 1666 | harry potter | toys (4 rows) omm=# select count(*) from products; omm=# count ------- 4 (1 row)
复制

4.查询表中所有category记录,并将查询结果按升序排序

omm=# select category from products order by category; category ---------------------- Books electrncs toys toys (4 rows)
复制

5.查询表中category为toys的记录

omm=# select * from products where category='toys'; product_id | product_name | category ------------+--------------------------------+---------------------- 1601 | lamaze | toys 1666 | harry potter | toys (2 rows)
复制

6.删除表products

omm=# drop table products; DROP TABLE omm=# \d No relations found.
复制

学习体会

为了进一步学习opengauss,原本打算在本地搭虚拟环境 openeuler+opengauss的,现在有了在线的opengauss,就节省了很多事情,谢谢社区的赋能。

初次接触墨天轮的在线环境,经过一节课的学习与适应,感觉很方便。

我写SQL的过程:

  1. 在本地装好插件的vscode上将代码写好复制到线上环境。
  2. 运行调试
  3. 将运行成功的SQL代码拷贝回本地并进行存储

学习资源


欢迎各位同学一起来交流学习心得!

最后修改时间:2021-12-16 18:37:01
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论