学习目标
学习查看表的相关信息
课程作业
1.创建表和约束
--创建表和约束
newdb1=# create table test(id bigint,name varchar(50) not null,age int default 20,primary key(id));
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "test_pkey" for table "test"
CREATE TABLE
复制
2.使用\d tableNmae命令查看表的定义、模式和所有者
newdb1=# \d+ test
Table "testsm.test"
Column | Type | Modifiers | Storage | Stats target | Description
--------+-----------------------+------------+----------+--------------+-------------
id | bigint | not null | plain | |
name | character varying(50) | not null | extended | |
age | integer | default 20 | plain | |
Indexes:
"test_pkey" PRIMARY KEY, btree (id) TABLESPACE newtbs1
Has OIDs: no
Options: orientation=row, compression=no
复制
3.查看某个模式下有哪些表
newdb1=# SELECT table_name FROM information_schema.tables WHERE table_schema='testsm';
table_name
------------
t1
testt1
testt2
test
(4 rows)
复制
4.查看一个表下有哪些约束
--可以看到约束是主键
newdb1=# \d test
Table "testsm.test"
Column | Type | Modifiers
--------+-----------------------+------------
id | bigint | not null
name | character varying(50) | not null
age | integer | default 20
Indexes:
"test_pkey" PRIMARY KEY, btree (id) TABLESPACE newtbs1
newdb1=# select conname, connamespace, contype, conkey
newdb1-# from pg_constraint
newdb1-# where conrelid in ( select oid
newdb1(# from pg_class
newdb1(# where relname='test');
conname | connamespace | contype | conkey
-----------+--------------+---------+--------
test_pkey | 24702 | p | {1}
(1 row)
复制
5.查看一个表属于数据库的哪个模式
newdb1=# select table_schema from information_schema.tables where table_name = 'test';
table_schema
--------------
testsm
(1 row)
复制
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论

2年前

评论
相关阅读
2025年3月国产数据库大事记
墨天轮编辑部
847次阅读
2025-04-03 15:21:16
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
MogDB
284次阅读
2025-04-17 10:41:41
openGauss 7.0.0-RC1 版本正式发布!
Gauss松鼠会
191次阅读
2025-04-01 12:27:03
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
云和恩墨
179次阅读
2025-04-16 09:52:02
openGauss 7.0.0-RC1 版本体验:一主一备快速安装指南
孙莹
171次阅读
2025-04-01 10:30:07
鲲鹏RAG一体机解决方案正式发布 openGauss DataVec向量数据库助力DeepSeek行业应用
Gauss松鼠会
112次阅读
2025-03-31 10:00:29
一文快速上手openGauss
进击的CJR
110次阅读
2025-03-26 16:12:54
openGauss6.0.0适配操作系统自带的软件,不依赖三方库
来杯拿铁
73次阅读
2025-04-18 10:49:53
opengauss使用gs_probackup进行增量备份恢复
进击的CJR
67次阅读
2025-04-09 16:11:58
荣誉时刻!openGauss认证证书快递已发,快来看看谁榜上有名!
墨天轮小教习
60次阅读
2025-04-23 17:39:13