openGauss每日一练第三天

这篇文章介绍了如何在openGauss中创建数据库(如tpcc1和tpcc2),修改数据库属性(如重命名),以及删除数据库。学习了使用SQL创建和查看数据库列表、修改数据库名和查看详细信息的方法。
摘要由CSDN通过智能技术生成

openGauss 每日一练第三天

本文出处:openGauss每日一练第二天 - 墨天轮

学习目标

学习 openGauss 创建数据库、修改数据库属性和删除数据库

课后作业

1.分别创建名为 tpcc1 和 tpcc2 的数据库

SQL文本:
create database tpcc1;
create database tpcc2;
\l

omm=# create database tpcc1;
CREATE DATABASE
omm=# create database tpcc2;
CREATE DATABASE
omm=# 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
 tpcc1     | omm   | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 tpcc2     | omm   | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
(6 rows)

omm=#

2.将 tpcc1 数据库重命名为 tpcc10

SQL文本:
alter database tpcc1 rename to tpcc10;

omm=# alter database tpcc1 rename to tpcc10;
ALTER DATABASE
omm=#

3.分别使用\l 和\l+两个元命令查看数据库信息

SQL文本:
\l
\l+

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
 tpcc10    | omm   | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 tpcc2     | omm   | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
(6 rows)

omm=# \l+
                                                               List of databases
   Name    | Owner | Encoding |   Collate   |    Ctype    | Access privileges | Size  | Tablespace |                Description
-----------+-------+----------+-------------+-------------+-------------------+-------+------------+--------------------------------------------
 omm       | omm   | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                   | 11 MB | pg_default |
 postgres  | omm   | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                   | 41 MB | pg_default | default administrative connection database
 template0 | omm   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/omm           +| 10 MB | pg_default | default template for new databases
           |       |          |             |             | omm=CTc/omm       |       |            |
 template1 | omm   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/omm           +| 10 MB | pg_default | unmodifiable empty database
           |       |          |             |             | omm=CTc/omm       |       |            |
 tpcc10    | omm   | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                   | 10 MB | pg_default |
 tpcc2     | omm   | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                   | 10 MB | pg_default |
(6 rows)

omm=#

4.在数据库 tpcc2 中创建 customer 表,字段自定义

SQL文本:
\c tpcc2
create table customer_t
(c_customer_sk             integer,
 c_customer_id             char(5),
 c_first_name              char(6),
 c_last_name               char(8)
 ) ;
 \d

tpcc2=# \c tpcc2
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "tpcc2" as user "omm".
tpcc2=# create table customer_t
tpcc2-# (c_customer_sk             integer,
tpcc2(#  c_customer_id             char(5),
tpcc2(#  c_first_name              char(6),
tpcc2(#  c_last_name               char(8)
tpcc2(#  ) ;
CREATE TABLE
tpcc2=# \d
                            List of relations
 Schema  |    Name    | Type  | Owner |             Storage
---------+------------+-------+-------+----------------------------------
 schema2 | customer_t | table | omm   | {orientation=row,compression=no}
(1 row)

tpcc2=#

5.删除新创建的数据库

SQL文本:
\c omm
drop database tpcc2;
drop database tpcc10;

tpcc2=# \c omm
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "omm" as user "omm".
omm=# drop database tpcc2;
DROP DATABASE
omm=# drop database tpcc10;
DROP DATABASE
omm=#

6.退出 gsql 程序

SQL文本:
\q

omm=# \q
[omm@modb ~]$
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值