February 11th, 2004, 04:50 PM
-
Copying tables BUT not data
How can I create a copy of a table without copying the data from the origional table
February 12th, 2004, 02:54 AM
-
CREATE TABLE new_table
AS
SELECT
* FROM old_table
WHERE 1=2;
But this will only recreate the structure of the table. Primary keys, foreign keys or other table constraints will not be copied.
February 13th, 2004, 01:40 PM
-
Originally Posted by shammat
CREATE TABLE new_table
AS
SELECT
* FROM old_table
WHERE 1=2;
But this will only recreate the structure of the table. Primary keys, foreign keys or other table constraints will not be copied.
Thanks for the help!
Do you know if there is a way to copy the columns over but not their data or definitions?
February 13th, 2004, 06:11 PM
-
Do the following :
Create new_table as
Select * from old_table where
rownum <1
This will give you an empty new table with the identical structure of the old table.
February 14th, 2004, 08:42 AM
-
Originally Posted by gdjsmith
Do you know if there is a way to copy the columns over but not their data or definitions?
What do you mean with that? My statement (ninakot's which is essentially the same as mine) will create a table with the same columns as the old one. No data will be copied.
A column needs a definition, so what would you want to copy if you omit the definition?
February 16th, 2004, 01:08 PM
-
Good Day,
CREATE TABLE <table characteristics> AS SELECT <query> is generally known as CTAS.
When you create a table using the subquery, only the NOT NULL constraints associated with the columns are copied to the new table. Other constraints and column default definitions are not copied.
Regards,
Dan