数据库环境
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的过程:
- 在本地装好插件的vscode上将代码写好复制到线上环境。
- 运行调试
- 将运行成功的SQL代码拷贝回本地并进行存储
学习资源
- openGauss SQL学习参考资料
- 每日一练:openGauss数据库在线实训课程
- openGauss每日一练 | 21期养成好习惯,提升技术能力!
- 墨天轮Markdown编辑器使用介绍
- 墨天轮数据库在线实训平台V1.0操作手册
- 墨天轮数据社区
欢迎各位同学一起来交流学习心得!
最后修改时间:2021-12-16 18:37:01
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
openGauss荣获中国软件行业协会多奖项,技术升级再创行业新高度
openGauss
457次阅读
2025-04-30 14:30:58
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
MogDB
300次阅读
2025-04-17 10:41:41
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
云和恩墨
198次阅读
2025-04-16 09:52:02
GitCode 成 openGauss 新归宿,国产开源数据库里程碑事件
严少安
155次阅读
2025-04-27 11:37:53
荣誉时刻!openGauss认证证书快递已发,快来看看谁榜上有名!
墨天轮小教习
150次阅读
2025-04-23 17:39:13
单个执行机并行执行MySQL到openGauss数据迁移子任务
Clipnosis
129次阅读
2025-04-30 16:39:58
openGauss6.0.0适配操作系统自带的软件,不依赖三方库
来杯拿铁
90次阅读
2025-04-18 10:49:53
opengauss使用gs_probackup进行增量备份恢复
进击的CJR
85次阅读
2025-04-09 16:11:58
Postgresql数据库单个Page最多存储多少行数据
maozicb
79次阅读
2025-04-23 16:02:19
openGauss新特性 | openGauss-DataVec向量数据库特性介绍
openGauss
49次阅读
2025-04-17 10:41:47