How to create a table from a select

sometime happen that you need to create a table from a query…
now we can assume that you have old_table and you wanna build a copi of entire data into another table new_table

This operation is not a standard sql but a lot DataBases can do this :

in Oracle you can do this like :

  1.  
  2.  
  3. CREATE TABLE new_table AS
  4. SELECT *
  5. FROM old_table
  6.  
  7.  

in MS Sql Server with this command :

  1.  
  2.  
  3. SELECT *
  4. INTO new_table
  5. FROM old_table
  6.  
  7.  

in mySql you can do this like (the only difference between Oracle is the “as” statement) :

  1.  
  2.  
  3. CREATE TABLE new_table
  4. AS
  5. SELECT *
  6. FROM old_table
  7.  
  8.  

Firebird don’t support this operation

for Oracle and Interbase we need to extend to temporary dynamic tables, and transactions interactions … for those we need an extension of this article…

i know that is simple, but only for reminder..
tnkx
i

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>