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

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

数据库环境

openGauss:2.0.0 - 数据库实训平台

学习目标

学习openGauss创建模式、修改模式属性和删除模式

学习笔记

  • 当schema非空时,如果要删除一个schema及其包含的所有对象,需要使用CASCADE关键字
omm=# ALTER SCHEMA ds_new OWNER TO jack; ALTER SCHEMA omm=# \dn+ ds_new; List of schemas Name | Owner | Access privileges | Description --------+-------+-------------------+------------- ds_new | jack | | (1 row) omm=# DROP SCHEMA ds_new; ERROR: cannot drop schema ds_new because other objects depend on it DETAIL: table ds_new.t1 depends on schema ds_new HINT: Use DROP ... CASCADE to drop the dependent objects too. omm=# DROP SCHEMA ds_new CASCADE; NOTICE: drop cascades to table ds_new.t1 DROP SCHEMA omm=# DROP USER jack; DROP ROLE

课后作业

1.创建一个名为tpcds的模式

omm=# create schema tpcds; CREATE SCHEMA omm=# \dn+ List of schemas Name | Owner | Access privileges | Description -------------+-------+-------------------+---------------------------------- cstore | omm | | reserved schema for DELTA tables dbe_perf | omm | | dbe_perf schema pkg_service | omm | | pkg_service schema public | omm | omm=UC/omm +| standard public schema | | =U/omm | snapshot | omm | | snapshot schema tpcds | omm | | (6 rows)

2.创建一个用户tim, 并将tpcds的owner修改为tim,且修改owner前后分别使用\dn+查看模式信息

omm=# create user tim identified by 'tim-user-pwd-12'; NOTICE: The encrypted password contains MD5 ciphertext, which is not secure. CREATE ROLE omm=# \du List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------------------------------------------------------------+----------- gaussdb | Sysadmin | {} omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {} tim | | {} omm=# alter schema tpcds owner to tim; ALTER SCHEMA omm=# \dn+ List of schemas Name | Owner | Access privileges | Description -------------+-------+-------------------+---------------------------------- cstore | omm | | reserved schema for DELTA tables dbe_perf | omm | | dbe_perf schema pkg_service | omm | | pkg_service schema public | omm | omm=UC/omm +| standard public schema | | =U/omm | snapshot | omm | | snapshot schema tim | tim | | tpcds | tim | | (7 rows) omm=#

3.重命名tpcds为tpcds1

omm=# alter schema tpcds rename to tpcds1; ALTER SCHEMA

4.在模式tpcds1中建表customer、插入记录和查询记录

omm=# create table tpcds1.customer(customer_id integer,customer_name char(30)); CREATE TABLE omm=# \d+ tpcds1.customer; Table "tpcds1.customer" Column | Type | Modifiers | Storage | Stats target | Description ---------------+---------------+-----------+----------+--------------+------------- customer_id | integer | | plain | | customer_name | character(30) | | extended | | Has OIDs: no Options: orientation=row, compression=no omm=# insert into tpcds1.customer values(1,'hello world'); INSERT 0 1 omm=# select * from tpcds1.customer; customer_id | customer_name -------------+-------------------------------- 1 | hello world (1 row)

5.删除模式tpcds1

omm=# drop schema tpcds1; ERROR: cannot drop schema tpcds1 because other objects depend on it DETAIL: table tpcds1.customer depends on schema tpcds1 HINT: Use DROP ... CASCADE to drop the dependent objects too. omm=# drop schema tpcds1 cascade; NOTICE: drop cascades to table tpcds1.customer DROP SCHEMA omm=# drop user tim; DROP ROLE omm=# \dn+ List of schemas Name | Owner | Access privileges | Description -------------+-------+-------------------+---------------------------------- cstore | omm | | reserved schema for DELTA tables dbe_perf | omm | | dbe_perf schema pkg_service | omm | | pkg_service schema public | omm | omm=UC/omm +| standard public schema | | =U/omm | snapshot | omm | | snapshot schema (5 rows) omm=# \du List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------------------------------------------------------------+----------- gaussdb | Sysadmin | {} omm | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {} omm=#

学习资源


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

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

评论