SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
DROP TABLE IF EXISTS organization; DROP SEQUENCE IF EXISTS organization_id_sq; CREATE SEQUENCE organization_id_sq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1; CREATE TABLE public.organization ( id integer DEFAULT nextval('organization_id_sq') NOT NULL, name character varying NOT NULL, license_number character varying NOT NULL, status character varying NOT NULL, CONSTRAINT organization_pkey PRIMARY KEY (id) ) WITH (oids = false); DROP TABLE IF EXISTS users; DROP SEQUENCE IF EXISTS users_id_sq; CREATE SEQUENCE users_id_sq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1; CREATE TABLE public.users ( id integer DEFAULT nextval('users_id_sq') NOT NULL, org_id integer NOT NULL, full_name character varying NOT NULL, email character varying NOT NULL, status character varying NOT NULL, CONSTRAINT users_pkey PRIMARY KEY (id), CONSTRAINT org_fkey FOREIGN KEY (org_id) REFERENCES organization (id) ) WITH (oids = false); DROP TABLE IF EXISTS roles; DROP SEQUENCE IF EXISTS roles_id_sq; CREATE SEQUENCE roles_id_sq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1; CREATE TABLE public.roles ( id integer DEFAULT nextval('roles_id_sq') NOT NULL, name character varying NOT NULL, CONSTRAINT roles_pkey PRIMARY KEY (id) ) WITH (oids = false); DROP TABLE IF EXISTS applications; DROP SEQUENCE IF EXISTS applications_id_sq; CREATE SEQUENCE applications_id_sq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1; CREATE TABLE public.applications ( id integer DEFAULT nextval('applications_id_sq') NOT NULL, name character varying NOT NULL, CONSTRAINT applications_pkey PRIMARY KEY (id) ) WITH (oids = false); DROP TABLE IF EXISTS branches; DROP SEQUENCE IF EXISTS branches_id_sq; CREATE SEQUENCE branches_id_sq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1; CREATE TABLE public.branches ( id integer DEFAULT nextval('branches_id_sq') NOT NULL, name character varying NOT NULL, account_id integer NOT NULL, CONSTRAINT branches_pkey PRIMARY KEY (id) ) WITH (oids = false); DROP TABLE IF EXISTS access_table; DROP SEQUENCE IF EXISTS access_id_sq; CREATE SEQUENCE access_id_sq INCREMENT 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1; CREATE TABLE public.access_table ( id integer DEFAULT nextval('access_id_sq') NOT NULL, user_id integer NOT NULL, branch_id integer NOT NULL, role_id integer NOT NULL, app_id integer NOT NULL, CONSTRAINT access_pkey PRIMARY KEY (id, user_id, role_id), CONSTRAINT branch_fkey FOREIGN KEY (branch_id) REFERENCES branches (id), CONSTRAINT app_fkey FOREIGN KEY (app_id) REFERENCES roles (id) ) WITH (oids = false); ALTER TABLE public.branches ADD CONSTRAINT account_fkey FOREIGN KEY (account_id) REFERENCES access_table (id)
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear