pgAdmin is the most popular and feature rich Open Source administration and development platform for PostgreSQL, the most advanced Open Source database in the world.
CREATE TABLE IF NOT EXISTS public.employees
(
employee_id integer NOT NULL,
first_name character varying(20),
last_name character varying(20) NOT NULL,
email character varying(100) NOT NULL,
phone_no character varying(20),
hire_date date NOT NULL,
job_id character varying(10) NOT NULL,
salary numeric(8, 2) NOT NULL,
commision_pct numeric(2, 2),
manager_id integer,
dep_id integer,
PRIMARY KEY (employee_id)
);
CREATE TABLE IF NOT EXISTS public.jobs
(
job_id character varying(10) NOT NULL,
job_title character varying(35) NOT NULL,
min_salary numeric,
max_salary numeric,
PRIMARY KEY (job_id)
);
CREATE TABLE IF NOT EXISTS public.departments
(
dep_id integer NOT NULL,
dep_name character varying(30) NOT NULL,
manager_id integer,
location_id integer,
PRIMARY KEY (dep_id)
);
CREATE TABLE IF NOT EXISTS public.locations
(
location_id integer NOT NULL,
street_address character varying(40),
postal_code character varying(12),
city character varying(30) NOT NULL,
state_province character varying(25),
country_id character(2) NOT NULL,
PRIMARY KEY (location_id)
);
ALTER TABLE IF EXISTS public.employees
ADD FOREIGN KEY (dep_id)
REFERENCES public.departments (dep_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.employees
ADD FOREIGN KEY (job_id)
REFERENCES public.jobs (job_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.departments
ADD FOREIGN KEY (location)
REFERENCES public.locations (location_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE IF EXISTS public.departments
ADD FOREIGN KEY (manager_id)
REFERENCES public.employees (employee_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
END;
----------------------------------- Error in Messages -----------------------------------
ERROR: current transaction is aborted, commands ignored until end of transaction block
-- This script was generated by the ERD tool in pgAdmin 4. -- Please log an issue at https://github.com/pgadmin-org/pgadmin4/issues/new/choose if you find any bugs, including reproduction steps.
BEGIN;
CREATE TABLE IF NOT EXISTS public.employees ( employee_id integer NOT NULL, first_name character varying(20), last_name character varying(20) NOT NULL, email character varying(100) NOT NULL, phone_no character varying(20), hire_date date NOT NULL, job_id character varying(10) NOT NULL, salary numeric(8, 2) NOT NULL, commision_pct numeric(2, 2), manager_id integer, dep_id integer, PRIMARY KEY (employee_id) );
CREATE TABLE IF NOT EXISTS public.jobs ( job_id character varying(10) NOT NULL, job_title character varying(35) NOT NULL, min_salary numeric, max_salary numeric, PRIMARY KEY (job_id) );
CREATE TABLE IF NOT EXISTS public.departments ( dep_id integer NOT NULL, dep_name character varying(30) NOT NULL, manager_id integer, location_id integer, PRIMARY KEY (dep_id) );
CREATE TABLE IF NOT EXISTS public.locations ( location_id integer NOT NULL, street_address character varying(40), postal_code character varying(12), city character varying(30) NOT NULL, state_province character varying(25), country_id character(2) NOT NULL, PRIMARY KEY (location_id) );
ALTER TABLE IF EXISTS public.employees ADD FOREIGN KEY (dep_id) REFERENCES public.departments (dep_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION NOT VALID;
ALTER TABLE IF EXISTS public.employees ADD FOREIGN KEY (job_id) REFERENCES public.jobs (job_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION NOT VALID;
ALTER TABLE IF EXISTS public.departments ADD FOREIGN KEY (location) REFERENCES public.locations (location_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION NOT VALID;
ALTER TABLE IF EXISTS public.departments ADD FOREIGN KEY (manager_id) REFERENCES public.employees (employee_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION NOT VALID;
END;
----------------------------------- Error in Messages ----------------------------------- ERROR: current transaction is aborted, commands ignored until end of transaction block
SQL state: 25P02