Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`show create table` equivalent in oracle sql

Tags:

sql

oracle

In MySql you can see the table definition (columns with their data types etc) with show create table table_name.

Is there a similar functionality for oracle sql?

like image 230
tymtam Avatar asked Aug 16 '13 01:08

tymtam


People also ask

How do I find the table created in SQL?

In the Object Explorer in SQL Server Management Studio, go to the database and expand it. Under the Tables folder select the table name. Right click and select Properties from the menu. You will see the created date of the table in the General section under Description.

What is CREATE TABLE in Oracle?

Use the CREATE TABLE statement to create one of the following types of tables: A relational table, which is the basic structure to hold user data. An object table, which is a table that uses an object type for a column definition. An object table is explicitly defined to hold object instances of a particular type.


1 Answers

If you are asking about SQL*Plus commands (show create table table_name doesn't appear to be a SQL statement), you can use the desc command

SQL> desc emp  Name                                      Null?    Type  ----------------------------------------- -------- ----------------------------  EMPNO                                     NOT NULL NUMBER(4)  ENAME                                              VARCHAR2(10)  JOB                                                VARCHAR2(9)  MGR                                                NUMBER(4)  HIREDATE                                           DATE  SAL                                                NUMBER(7,2)  COMM                                               NUMBER(7,2)  DEPTNO                                             NUMBER(2) 

If you really want a SQL statement, you can use the dbms_metadata package

  1  select dbms_metadata.get_ddl( 'TABLE', 'EMP', 'SCOTT' )   2*   from dual SQL> /  DBMS_METADATA.GET_DDL('TABLE','EMP','SCOTT') --------------------------------------------------------------------------------    CREATE TABLE "SCOTT"."EMP"    (    "EMPNO" NUMBER(4,0),         "ENAME" VARCHAR2(10),         "JOB" VARCHAR2(9),         "MGR" NUMBER(4,0),         "HIREDATE" DATE,         "SAL" NUMBER(7,2),         "COMM" NUMBER(7,2),         "DEPTNO" NUMBER(2,0),          CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO")   USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS   STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645   PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE FAULT CELL_FLASH_CACHE DEFAULT)   TABLESPACE "USERS"   ALTER INDEX "SCOTT"."PK_EMP"  UNUSABLE ENABLE,          CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO")           REFERENCES "SCOTT"."DEPT" ("DEPTNO") ENABLE    ) SEGMENT CREATION IMMEDIATE   PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING   STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645   PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DE FAULT CELL_FLASH_CACHE DEFAULT)   TABLESPACE "USERS"   CACHE 

Depending on the tool you are using, you may need to run set long 10000 first, that tells SQL*Plus to display the first 10,000 bytes of any LOB that is selected. If your DDL is longer, set a larger value.

like image 164
Justin Cave Avatar answered Sep 30 '22 07:09

Justin Cave