How to copy structure of one table to another with foreign key constraints in psql?
问题 Foreign key constraints are not copied when using create table table_name ( like source_table INCLUDING ALL)' in Postgres. How can I create a copy of an existing table including all foreign keys. 回答1: There is no option to automatically create foreign keys in CREATE TABLE ... LIKE ... . For the documentation: LIKE source_table [ like_option ... ] Not-null constraints are always copied to the new table. CHECK constraints will be copied only if INCLUDING CONSTRAINTS is specified [...] Indexes,