Wednesday, August 31, 2016

Create a new table using schema (columns) and / or data from an existing table in Oracle and PostgreSQL

A. Oracle

1. Create a new table using the complete schema and data from an existing table.

      create table <new table name> as select * from <existing table name>;

2. Create a new table using partial of the schema and data of an existing table.

      create table <new table name> as select <column 1>, <column 2>, .... from <existing table name>;

     The new table would have only the columns and their data selected from the existing table.

3. Create a new table using the schema but not data from an existing table.

      create table <new table name> as select * from <existing table name> where 1=0;
      create table <new table name> as select <column 1><column 2>, .... from <existing table name> where 1=0;

B. PostgreSQL

1. Create a new table using the complete schema and data from an existing table.

      select * into <new table name> from <existing table name>;

2. Create a new table using partial of the schema and data of an existing table.

      select <column 1><column 2>, .... into <new table name> from <existing table name>;

3. Create a new table using the schema but not data from an existing table.

      select * into <new table name> from <existing table name> where 1=0;
      select <column 1><column 2>, .... into <new table name> from <existing table name> where 1=0;

---------------------------------------------------------------------------------------------------

                        

If you have ever asked yourself these questions, this is the book for you. What is the meaning of life? Why do people suffer? What is in control of my life? Why is life the way it is? How can I stop suffering and be happy? How can I have a successful life? How can I have a life I like to have? How can I be the person I like to be? How can I be wiser and smarter? How can I have good and harmonious relations with others? Why do people meditate to achieve enlightenment? What is the true meaning of spiritual practice? Why all beings are one? Read the book free here.

No comments:

Post a Comment