Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show the structure of the table in SQL

Tags:

sql

sqlplus

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>
like image 434
user770022 Avatar asked Sep 09 '11 01:09

user770022


People also ask

How do you display the structure of a table in SQL?

SQL Server: sp_help table_name (or sp_columns table_name for only columns) Oracle DB2: desc table_name or describe table_name. MySQL: describe table_name (or show columns from table_name for only columns)

How can you view the structure of a table?

- The structure of a table can be viewed using the DESCRIBE TABLE_NAME command. - Provides a description of the specified table or view. For a list of tables in the current schema, use the Show Tables command.

What is table structure in SQL?

The tables are the database objects that behave as containers for the data, in which the data will be logically organized in rows and columns format. Each row is considered as an entity that is described by the columns that hold the attributes of the entity.


3 Answers

Try this out: describe table_name

like image 175
sribin Avatar answered Oct 17 '22 15:10

sribin


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

like image 18
Michael Berkowski Avatar answered Oct 17 '22 17:10

Michael Berkowski


You can use sqlplus command describe <SCHEMA_OWNER.TABLE>

https://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12019.htm

like image 1
AlexPes Avatar answered Oct 17 '22 16:10

AlexPes