\d test.table2 begin; alter table "test"."table2" drop constraint "table2_table1_id_fkey"; alter table "test"."table2" drop constraint "table2_pkey"; drop index "test"."testindex"; copy "test"."table2" from stdin; 1 test \. analyze "test"."table2"; alter table "test"."table2" add primary key ("table1_id"); create index "testindex" on "test"."table2" ("value"); alter table "test"."table2" add foreign key ("table1_id") references "test"."table1" ("id"); commit; \d test.table2