34

I want to save a copy of specific table with it's data. All I care is the structure and data. I don't want to copy the keys nor constrains.

I read this answer Copy table structure into new table but it's not quite what I need.

How it can be done?

1
  • 3
    create table copy_table as select * from original table ?.. Commented Apr 6, 2017 at 7:35

1 Answer 1

58

You are probably looking for CREATE TABLE AS SELECT, e.g.:

CREATE TABLE copy_table AS SELECT * FROM original_table;
Sign up to request clarification or add additional context in comments.

4 Comments

"original table" ---> original_table ;-)
CREATE TABLE copy_table AS TABLE original_table; - shorthand version
yes, but TABLE is much less flexible than SELECT - I would prefer answering it with select, as you can add any where or whatever to a statement, not just limit or what the possible option list it
and if you just want the table structure, without the data you can add WHERE 1=0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.