Search code examples
sqloracle-databasecopydatabase-table

How can I create a copy of an Oracle table without copying the data?


I know the statement:

create table xyz_new as select * from xyz;

Which copies the structure and the data, but what if I just want the structure?


Solution

  • Just use a where clause that won't select any rows:

    create table xyz_new as select * from xyz where 1=0;
    

    Limitations

    The following things will not be copied to the new table:

    • sequences
    • triggers
    • indexes
    • some constraints may not be copied
    • materialized view logs

    This also does not handle partitions