Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

A question about how to copy one table into another

dariyooshJan 28 2010 — edited Jan 28 2010
Hello everybody,


I have a question related to how to copy one table into another. Suppose that I have one table named "table1". What I want to do is to create another table named "table2" that contains exactly the same data stored in "table1". Here is how I usually proceed.
CREATE TABLE table2 AS
SELECT *
FROM table1;
Well, this works and it injects the whole set of data stored in "table1" into the table "table2". Yet, I noticed that by this method, not all the constraints of the "table1" are copied in "table2". I mean, all columns that were declared "NOT NULL" during "table1" definition are also considered to be "NOT NULL" in "table2". But other constraints such as primaery key, foreigne keys, etc. are not copied.

What I would like to know is whether there is a command allowing to do a deep copy, that is, copy both data and the whole set of the associated constraints from one table into another. In other words, creating the very same table just by a different name.

Thanks in advance,


Kind Regards,
Dariyoosh
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 25 2010
Added on Jan 28 2010
2 comments
1,210 views