Show the structure of the table in SQL

强颜欢笑 提交于 2019-12-23 07:37:10

问题


Can someone explain things a little better to me? How do I show the structure of a table? I run the select * from table; and of course it displays all that's in the table. But, I am being asked to show the structure of the table. What does that mean, and what is the command?

Here's my table below.

SQL> select * from dept;

DEPTNO DNAME          LOC
---------- -------------- -------------
    10 ACCOUNTING     NEW YORK
    20 RESEARCH       DALLAS
    30 SALES          CHICAGO
    40 OPERATIONS     BOSTON

 SQL>

回答1:


To list columns and data types, I typically use

SELECT COLUMN_NAME, DATA_TYPE FROM ALL_TAB_COLUMNS WHERE TABLE_NAME='your_table_name';

It's been a while since I've worked with Oracle though. ALL_TAB_COLUMNS might actually be ALL_TAB_COLS.

If you need to display the full CREATE TABLE statement, see How to get Oracle create table statement in SQL*Plus




回答2:


Try this out: describe table_name



来源:https://stackoverflow.com/questions/7356338/show-the-structure-of-the-table-in-sql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!