I want to create a new table with properties of an old table and without duplicates. I want to do something like this:
CREATE TABLE New_Users LIKE Old_Users, AS (SELECT * FROM Old_Users GROUP BY ID) ;
But the above is not working. Can anybody modify it to work?
The SELECT privilege is required on the original table. LIKE works only for base tables, not for views. You cannot execute CREATE TABLE or CREATE TABLE ... LIKE while a LOCK TABLES statement is in effect.
Answer: To do this, the SQL CREATE TABLE syntax is: CREATE TABLE new_table AS (SELECT * FROM old_table WHERE 1=2); For example: CREATE TABLE suppliers AS (SELECT * FROM companies WHERE 1=2);
Question: How can I create an Oracle table from another table without copying any values from the old table? Answer: To do this, the Oracle CREATE TABLE syntax is: CREATE TABLE new_table AS (SELECT * FROM old_table WHERE 1=2);
Your attempt wasn't that bad. You have to do it with LIKE
, yes.
In the manual it says:
Use LIKE to create an empty table based on the definition of another table, including any column attributes and indexes defined in the original table.
So you do:
CREATE TABLE New_Users LIKE Old_Users;
Then you insert with
INSERT INTO New_Users SELECT * FROM Old_Users GROUP BY ID;
But you can not do it in one statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With