HomeMogDBMogDB StackUqbar
v5.0

Documentation:v5.0

Supported Versions:

Other Versions:

DESCRIBE

Function

Views the structure of a specified table.

Precautions

  • You need to specify the schema corresponding to the temporary table for query.
  • All participating columns of a composite primary key index are displayed as PRI in the Key column.
  • All participating columns of the composite unique index are displayed as UNI in the Key column.
  • If a column is involved in the creation of multiple indexes, the Key column is displayed based on the first index created in the column.
  • The generated column is displayed in Default.
  • Table synonyms are not supported.

Syntax

{DESCRIBE | DESC} tbl_name

Parameter Description

  • {DESCRIBE | DESC}

     The effect of using DESCRIBE is equivalent to that of using DESCRIBE.
  • tbl_name

     Table name. You can specify a table name or **schema\_name.table\_name**.

Examples

--Create a test table.
MogDB=# CREATE TABLE test2
MogDB-# (
MogDB(# id int PRIMARY KEY
MogDB(# );
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "test2_pkey" for table "test2"
CREATE TABLE
MogDB=# create table test
MogDB-# (
MogDB(# a SERIAL,
MogDB(# b varchar(10),
MogDB(# c varchar(10),
MogDB(# d varchar(10),
MogDB(# e varchar(10),
MogDB(# f varchar(10),
MogDB(# g varchar(10) DEFAULT 'g',
MogDB(# h varchar(10) NOT NULL,
MogDB(# i int DEFAULT 0,
MogDB(# j int DEFAULT 0,
MogDB(# k int GENERATED ALWAYS AS (i + j) STORED,
MogDB(# l int DEFAULT 0,
MogDB(# m int CHECK (m < 50),
MogDB(# PRIMARY KEY (a, b),
MogDB(# FOREIGN KEY(l) REFERENCES test2(id)
MogDB(# );
NOTICE:  CREATE TABLE will create implicit sequence "test_a_seq" for serial column "test.a"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "test_pkey" for table "test"
CREATE TABLE
MogDB=# CREATE UNIQUE INDEX idx_c on test (c);
CREATE INDEX
MogDB=# CREATE UNIQUE INDEX idx_d_e on test (d, e);
CREATE INDEX
MogDB=# CREATE INDEX idx_f on test (f);
CREATE INDEX

--View the structure of the test table.
MogDB=# desc test;
 Field |         Type          | Null | Key |             Default             | Extra
-------+-----------------------+------+-----+---------------------------------+-------
 a     | integer               | NO   | PRI | nextval('test_a_seq'::regclass) |
 b     | character varying(10) | NO   | PRI | NULL                            |
 c     | character varying(10) | YES  | UNI | NULL                            |
 d     | character varying(10) | YES  | UNI | NULL                            |
 e     | character varying(10) | YES  | UNI | NULL                            |
 f     | character varying(10) | YES  | MUL | NULL                            |
 g     | character varying(10) | YES  |     | 'g'::character varying          |
 h     | character varying(10) | NO   |     | NULL                            |
 i     | integer               | YES  |     | 0                               |
 j     | integer               | YES  |     | 0                               |
 k     | integer               | YES  |     | (i + j)                         |
 l     | integer               | YES  | MUL | 0                               |
 m     | integer               | YES  |     | NULL                            |
(13 rows)

MogDB=# desc public.test;
 Field |         Type          | Null | Key |             Default             | Extra
-------+-----------------------+------+-----+---------------------------------+-------
 a     | integer               | NO   | PRI | nextval('test_a_seq'::regclass) |
 b     | character varying(10) | NO   | PRI | NULL                            |
 c     | character varying(10) | YES  | UNI | NULL                            |
 d     | character varying(10) | YES  | UNI | NULL                            |
 e     | character varying(10) | YES  | UNI | NULL                            |
 f     | character varying(10) | YES  | MUL | NULL                            |
 g     | character varying(10) | YES  |     | 'g'::character varying          |
 h     | character varying(10) | NO   |     | NULL                            |
 i     | integer               | YES  |     | 0                               |
 j     | integer               | YES  |     | 0                               |
 k     | integer               | YES  |     | (i + j)                         |
 l     | integer               | YES  | MUL | 0                               |
 m     | integer               | YES  |     | NULL                            |
(13 rows)

MogDB=# describe public.test;
 Field |         Type          | Null | Key |             Default             | Extra
-------+-----------------------+------+-----+---------------------------------+-------
 a     | integer               | NO   | PRI | nextval('test_a_seq'::regclass) |
 b     | character varying(10) | NO   | PRI | NULL                            |
 c     | character varying(10) | YES  | UNI | NULL                            |
 d     | character varying(10) | YES  | UNI | NULL                            |
 e     | character varying(10) | YES  | UNI | NULL                            |
 f     | character varying(10) | YES  | MUL | NULL                            |
 g     | character varying(10) | YES  |     | 'g'::character varying          |
 h     | character varying(10) | NO   |     | NULL                            |
 i     | integer               | YES  |     | 0                               |
 j     | integer               | YES  |     | 0                               |
 k     | integer               | YES  |     | (i + j)                         |
 l     | integer               | YES  | MUL | 0                               |
 m     | integer               | YES  |     | NULL                            |
(13 rows)

N/A

Copyright © 2011-2024 www.enmotech.com All rights reserved.