16 lines
979 B
SQL
16 lines
979 B
SQL
-- Create "PostalRegion" table
|
|
CREATE TABLE "public"."PostalRegion" (
|
|
"Id" bigserial NOT NULL,
|
|
"Village_Code" character varying(10) NULL,
|
|
"Code" character varying(5) NULL,
|
|
PRIMARY KEY ("Id"),
|
|
CONSTRAINT "uni_PostalRegion_Code" UNIQUE ("Code"),
|
|
CONSTRAINT "fk_PostalRegion_Village" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION
|
|
);
|
|
-- Rename a column from "PostalCode_Code" to "PostalRegion_Code"
|
|
ALTER TABLE "public"."PersonAddress" RENAME COLUMN "PostalCode_Code" TO "PostalRegion_Code";
|
|
-- Modify "PersonAddress" table
|
|
ALTER TABLE "public"."PersonAddress" DROP CONSTRAINT "fk_PersonAddress_PostalCode", ADD COLUMN "LocationType_Code" character varying(10) NULL, ADD CONSTRAINT "fk_PersonAddress_PostalRegion" FOREIGN KEY ("PostalRegion_Code") REFERENCES "public"."PostalRegion" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
|
|
-- Drop "PostalCode" table
|
|
DROP TABLE "public"."PostalCode";
|