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?
Join Stack Overflow to learn, share knowledge, and build your career.
|
I know the statement:
Which copies the structure and the data, but what if I just want the structure? |
|||||
|
|
Just use a where clause that won't select any rows:
LimitationsThe following things will not be copied to the new table:
This also does not handle partitions |
|||||||||||||||||||||
|
|
I used the method that you accepted a lot, but as someone pointed out it doesn't duplicate constraints (except for NOT NULL, I think). A more advanced method if you want to duplicate the full structure is:
This will give you the full create statement text which you can modify as you wish for creating the new table. You would have to change the names of the table and all constraints of course. (You could also do this in older versions using EXP/IMP, but it's much easier now.) Edited to add If the table you are after is in a different schema:
|
|||||||||||||||||
|
|
Using sql developer select the table and click on the DDL tab You can use that code to create a new table with no data when you run it in a sql worksheet sqldeveloper is a free to use app from oracle. If the table has sequences or triggers the ddl will sometimes generate those for you too. You just have to be careful what order you make them in and know when to turn the triggers on or off. |
||||
|
|
To avoid iterate again and again and insert nothing based on the condition where 1=2 |
||||
|
|
|
You can do this
|
|||
|
|
|
Simply write a query like:
where |
||||
|
|
|
Use example :
source : http://forgetcode.com/Teradata/1209-COPY-TABLE-STRUCTURE-and-DATA |
|||||
|
|
|||
|
|
Create a new, empty table using the schema of another. Just add a WHERE clause that causes the query to return no data: |
|||
|
|
|
you can also do a
then truncate the table |
|||||
|
Source_table is the table u wanna copy the structure of. |
||||
|
|
|
Using pl/sql developer you can right click on the table_name either in the sql workspace or in the object explorer, than click on "view" and than click "view sql" which generates the sql script to create the table along with all the constraints, indexes, partitions etc.. Next you run the script using the new_table_name |
||||
|
|
|
In other way you can get ddl of table creation from command listed below, and execute the creation.
With this command you can get majority of ddl from database objects. |
||||
|
|
copy without table data
copy with table data
|
|||
|
|
|
The task above can be completed in two simple steps. STEP 1:
The To get the structure, delete the contents of the table using. STEP 2:
Hope this solves your problem. And thanks to the earlier posts. Gave me a lot of insight. |
|||||
|