Random Oracle Tip: Duplicating a Table Structure

I think this is well known, but since I use it from time to time, I'm going to repeat it. If you need to duplicate a table's structure for some reason, then all you need to do is this:

CREATE TABLE new_table as (select * from old_table WHERE 1=0)

This will copy the table structure without any of the data since one can never equal zero.

No comments yet. Be the first.

Leave a reply