Feature Post

Top

CREATE TABLE FROM SELECT STAR

This answers the questions:
  • How to create a new table(on the fly) out of a query result?
  • How to copy schema into a new table out of a query result?
SQL Server:


   1: SELECT * INTO NEW_TABLE 
   2:  FROM SOURCE_TABLE 

mySQL:


   1: CREATE TABLE NEW_TABLE 
   2:  SELECT * FROM SOURCE_TABLE; 

Oracle:

   1: SELECT * INTO NEW_TABLE
   2:  FROM SOURCE_TABLE 

or

   1: SELECT Col1, Col2, Col_n INTO NEW_TABLE
   2:  FROM SOURCE_TABLE 

Postgre SQL:

   1: CREATE TABLE NEW_TABLE
   2:  AS SELECT * FROM SOURCE_TABLE;

Note, you can always use WHERE 1=0  if you want to copy only schema.

exploits_of_a_mom

Enjoy!