openGauss每日一练第三天

openGauss 每日一练第三天
本文出处:https://www.modb.pro/db/193083

学习目标
学习 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 ~]$

posted @   openGaussbaby  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示