In an Oracle 10g database, I would like to make a copy of an existing table. I would like it to have the same data and rows as the original table. The original table uses a PK though, so I'm not sure how to copy it and keep them unique.
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
You can make the copy using
Also you could use dbms_metadata.get_ddl to get the associated constraints of the table and create it with all the checks
oracle maintains the pk as a column constraint. you have to copy the table and subsequently create this constraint for the new table.
the following code illustrates how to get your job done.
hope this helps,
best regards,
carsten
Or you can just do it all in one statement:
I think the format of specifying column names when using
create table as select
is a bit fiddly in that I don't believe that you can specify data types (sort of obvious really) but you can specify constraints such asnot null
, primary key and foreign key.