如何在 SQL 中打印表的结构及其内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4549251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 08:42:25  来源:igfitidea点击:

How to print the structure of a table and its contents in SQL

sqldatabaseoracleprinting

提问by John Stevens

I've created a simple database using Oracle SQL (iSQL plus). How can I print the table structure and its contents?

我使用 Oracle SQL (iSQL plus) 创建了一个简单的数据库。如何打印表结构及其内容?

采纳答案by Leniel Maccaferri

I know the desccommand:

我知道desc命令:

http://www.riteshmandal.com/oracle.htm

http://www.riteshmandal.com/oracle.htm

DESC or DESCRIBE : Used to describe the table structure present in the tablespace.

USE : DESC e.g. DESC Employee;

USE : SELECT * FROM to view all the data inside the table. e.g. SELECT * FROM Employee

DESC 或 DESCRIBE :用于描述表空间中存在的表结构。

用途:DESC,例如DESC Employee;

USE : SELECT * FROM 查看表内的所有数据。例如 SELECT * FROM 员工

Example:

例子:

SQL> -- create demo table
SQL> create table Employee(
  2    ID                 VARCHAR2(4 BYTE)         NOT NULL,
  3    First_Name         VARCHAR2(10 BYTE),
  4    Last_Name          VARCHAR2(10 BYTE),
  5    Start_Date         DATE,
  6    End_Date           DATE,
  7    Salary             Number(8,2),
  8    City               VARCHAR2(10 BYTE),
  9    Description        VARCHAR2(15 BYTE)
 10  )
 11  /

Table created.

SQL>
SQL> desc Employee;
 Name           Null?    Type
-------------------------------------------
 ID            NOT NULL   VARCHAR2(4)
 FIRST_NAME               VARCHAR2(10)
 LAST_NAME                VARCHAR2(10)
 START_DATE               DATE
 END_DATE                 DATE
 SALARY                   NUMBER(8,2)
 CITY                     VARCHAR2(10)
 DESCRIPTION              VARCHAR2(15)

SQL>
SQL>
SQL>
SQL> -- clean the table
SQL> drop table Employee
  2  /

Table dropped.

SQL>

回答by dvb

Two different queries will be used for this. The table to show the table structure is:

为此将使用两个不同的查询。显示表结构的表是:

describe <table_name>;
or
describe table <table_name>;

描述<table_name>;

描述表<table_name>