今日学习了openGauss的简单的表管理,如何在不同模式下创建表和不同搜索路径的访问方法。
#登录数据库
su - omm
gsql -r1、创建一个表(默认,不指定模式),查看该表在哪个模式下。
create table t1(id int);
\dt t1
2、使用一个用户连接到enmdb数据库,测试该用户可以访问不同模式中的表。
#创建表空间、数据库、用户
create tablespace enmtbs relative location 'tablespace/enmtbs1';
create database enmdb with tablespace=enmtbs;
create user cherish identified by 'kunpeng@1234';
alter user cherish sysadmin;
#创建模式 \c enmdb cherishcreate schema enmschm; create schema enmschm1; create schema enmschm2;
#在不同模式建表,插入记录
create table enmschm.t1(col varchar(100));
insert into enmschm.t1 values('hello this is enmschm schema!');
create table enmschm1.t1(col varchar(100));
insert into enmschm1.t1 values('hello this is enmschm1 schema!');
create table enmschm2.t1(col varchar(100));
insert into enmschm2.t1 values('hello this is enmschm2 schema!');#访问不同模式的表
select * from enmschm.t1;
select * from enmschm1.t1;
select * from enmschm2.t1;
3、在会话级设置模式搜索路径为:模式enmschm1,使用SchemaName.TableName的表标识方法访问表(创建表、插入数据和查询表中的数据)
#设置会话模式搜索路径enmschm1set search_path to enmschm1;
create table enmschm1.t1(col varchar(100)); insert into enmschm1.t1 values('hello this is enmschm1 schema!'); select * from enmschm1.t1;
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。





