Differences

This shows you the differences between two versions of the page.

Link to this comparison view

copy_table_to_another_schema [2013/10/02 09:12]
copy_table_to_another_schema [2021/04/05 11:23] (current)
Line 1: Line 1:
 +====== Copy Table to another Schema ======
  
 +===== The SQL Way =====
 +
 +  CREATE TABLE new_schema.my_table  (LIKE other_schema.my_table INCLUDING DEFAULTS INCLUDING INDEXES INCLUDING CONSTRAINTS);
 +  
 +<note>The INCLUDING keywords are PostgreSQL specific. Regardless of the INCLUDING CONSTRAINTS keywords foreign constraints will not be copied/created.</note>
 +
 +To copy the contents just use an INSERT statement like this:
 +
 +  INSERT INTO new_schema.my_table SELECT * FROM other_schema.my_table;
 +
 +{{tag>sql}}