text: -- This script was generated by a beta version of the ERD tool in pgAdmin 4.
  -- Please log an issue at https://redmine.postgresql.org/projects/pgadmin4/issues/new if you find any bugs, including reproduction steps.
  BEGIN;
  
  
  CREATE TABLE IF NOT EXISTS public.avales
  (
      id_aval integer NOT NULL DEFAULT nextval('avales_id_aval_seq'::regclass),
      nombre character varying(50) COLLATE pg_catalog."default",
      apellidos character varying(50) COLLATE pg_catalog."default",
      direccion character varying(50) COLLATE pg_catalog."default",
      telefono bigint,
      id_credito integer,
      CONSTRAINT avales_pkey PRIMARY KEY (id_aval)
  );
  
  CREATE TABLE IF NOT EXISTS public.clientes
  (
      id_cliente integer NOT NULL DEFAULT nextval('clientes_id_cliente_seq'::regclass),
      nombre character varying(50) COLLATE pg_catalog."default",
      apellido character varying(50) COLLATE pg_catalog."default",
      genero character(1) COLLATE pg_catalog."default",
      calle character varying(50) COLLATE pg_catalog."default",
      numero_ext integer,
      colonia character varying(25) COLLATE pg_catalog."default",
      cp integer,
      ciudad character varying(30) COLLATE pg_catalog."default",
      municipio character varying(50) COLLATE pg_catalog."default",
      estado character varying(30) COLLATE pg_catalog."default",
      telefono_casa bigint,
      telefono_cel bigint,
      rfc character varying(15) COLLATE pg_catalog."default",
      correo character varying(50) COLLATE pg_catalog."default",
      activo boolean,
      id_sucursal integer,
      CONSTRAINT clientes_pkey PRIMARY KEY (id_cliente)
  );
  
  CREATE TABLE IF NOT EXISTS public.creditos
  (
      id_credito integer NOT NULL DEFAULT nextval('creditos_id_credito_seq'::regclass),
      fecha_solicitud date,
      fecha_aprobacion date,
      monto_solicitado double precision,
      monto_otorgado double precision,
      status boolean,
      plazo_deuda date,
      intereses double precision,
      comision double precision,
      id_cliente integer,
      id_ejecutivo integer,
      CONSTRAINT creditos_pkey PRIMARY KEY (id_credito)
  );
  
  CREATE TABLE IF NOT EXISTS public.cuentas
  (
      id_cuenta integer NOT NULL DEFAULT nextval('cuentas_id_cuenta_seq'::regclass),
      tipo character(1) COLLATE pg_catalog."default",
      fecha_creacion date,
      estado boolean,
      monto double precision,
      comision double precision,
      limite_credito double precision,
      id_cliente integer,
      CONSTRAINT cuentas_pkey PRIMARY KEY (id_cuenta)
  );
  
  CREATE TABLE IF NOT EXISTS public.denominaciones
  (
      id_denominacion integer NOT NULL DEFAULT nextval('denominaciones_id_denominacion_seq'::regclass),
      billete_20 integer,
      billete_50 integer,
      billete_100 integer,
      billete_200 integer,
      billete_500 integer,
      billete_1000 integer,
      moneda_10c integer,
      moneda_50c integer,
      moneda_1p integer,
      moneda_2p integer,
      moneda_5p integer,
      moneda_10p integer,
      moneda_20p integer,
      id_transaccion integer,
      CONSTRAINT denominaciones_pkey PRIMARY KEY (id_denominacion)
  );
  
  CREATE TABLE IF NOT EXISTS public.ejecutivos
  (
      id_ejecutivo integer NOT NULL DEFAULT nextval('ejecutivos_id_ejecutivo_seq'::regclass),
      nombre character varying(50) COLLATE pg_catalog."default",
      apellido character varying(50) COLLATE pg_catalog."default",
      area character varying(10) COLLATE pg_catalog."default",
      puesto character varying(10) COLLATE pg_catalog."default",
      clave integer,
      "contraseña" character varying(10) COLLATE pg_catalog."default",
      status character varying(6) COLLATE pg_catalog."default",
      id_sucursal integer,
      CONSTRAINT ejecutivos_pkey PRIMARY KEY (id_ejecutivo)
  );
  
  CREATE TABLE IF NOT EXISTS public.sucursales
  (
      id_sucursal integer NOT NULL DEFAULT nextval('sucursales_id_sucursal_seq'::regclass),
      nombre character varying(50) COLLATE pg_catalog."default",
      direccion character varying(50) COLLATE pg_catalog."default",
      email character varying(30) COLLATE pg_catalog."default",
      ceo character varying(50) COLLATE pg_catalog."default",
      descripcion character varying(100) COLLATE pg_catalog."default",
      seguridad character varying(50) COLLATE pg_catalog."default",
      CONSTRAINT sucursales_pkey PRIMARY KEY (id_sucursal)
  );
  
  CREATE TABLE IF NOT EXISTS public.tarjetas
  (
      id_numero_tarjeta character varying(16) COLLATE pg_catalog."default" NOT NULL,
      nip integer,
      fecha_vencimiento date,
      id_cuenta integer,
      CONSTRAINT tarjetas_pkey PRIMARY KEY (id_numero_tarjeta)
  );
  
  CREATE TABLE IF NOT EXISTS public.transacciones
  (
      id_transaccion integer NOT NULL DEFAULT nextval('transacciones_id_transaccion_seq'::regclass),
      monto_inicial double precision,
      monto_final double precision,
      fecha date,
      tipo character varying(10) COLLATE pg_catalog."default",
      cantidad double precision,
      id_cuenta integer,
      id_ejecutivo integer,
      CONSTRAINT transacciones_pkey PRIMARY KEY (id_transaccion)
  );
  
  ALTER TABLE IF EXISTS public.avales
      ADD CONSTRAINT avales_id_credito_fkey FOREIGN KEY (id_credito)
      REFERENCES public.creditos (id_credito) MATCH SIMPLE
      ON UPDATE NO ACTION
      ON DELETE NO ACTION;
  
  
  ALTER TABLE IF EXISTS public.clientes
      ADD CONSTRAINT clientes_id_sucursal_fkey FOREIGN KEY (id_sucursal)
      REFERENCES public.sucursales (id_sucursal) MATCH SIMPLE
      ON UPDATE NO ACTION
      ON DELETE NO ACTION;
  
  
  ALTER TABLE IF EXISTS public.creditos
      ADD CONSTRAINT creditos_id_cliente_fkey FOREIGN KEY (id_cliente)
      REFERENCES public.clientes (id_cliente) MATCH SIMPLE
      ON UPDATE NO ACTION
      ON DELETE NO ACTION;
  
  
  ALTER TABLE IF EXISTS public.creditos
      ADD CONSTRAINT creditos_id_ejecutivo_fkey FOREIGN KEY (id_ejecutivo)
      REFERENCES public.ejecutivos (id_ejecutivo) MATCH SIMPLE
      ON UPDATE NO ACTION
      ON DELETE NO ACTION;
  
  
  ALTER TABLE IF EXISTS public.cuentas
      ADD CONSTRAINT cuentas_id_cliente_fkey FOREIGN KEY (id_cliente)
      REFERENCES public.clientes (id_cliente) MATCH SIMPLE
      ON UPDATE NO ACTION
      ON DELETE NO ACTION;
  
  
  ALTER TABLE IF EXISTS public.denominaciones
      ADD CONSTRAINT denominaciones_id_transaccion_fkey FOREIGN KEY (id_transaccion)
      REFERENCES public.transacciones (id_transaccion) MATCH SIMPLE
      ON UPDATE NO ACTION
      ON DELETE NO ACTION;
  
  
  ALTER TABLE IF EXISTS public.ejecutivos
      ADD CONSTRAINT ejecutivos_id_sucursal_fkey FOREIGN KEY (id_sucursal)
      REFERENCES public.sucursales (id_sucursal) MATCH SIMPLE
      ON UPDATE NO ACTION
      ON DELETE NO ACTION;
  
  
  ALTER TABLE IF EXISTS public.tarjetas
      ADD CONSTRAINT tarjetas_id_cuenta_fkey FOREIGN KEY (id_cuenta)
      REFERENCES public.cuentas (id_cuenta) MATCH SIMPLE
      ON UPDATE NO ACTION
      ON DELETE NO ACTION;
  
  
  ALTER TABLE IF EXISTS public.transacciones
      ADD CONSTRAINT transacciones_id_cuenta_fkey FOREIGN KEY (id_cuenta)
      REFERENCES public.cuentas (id_cuenta) MATCH SIMPLE
      ON UPDATE NO ACTION
      ON DELETE NO ACTION;
  
  
  ALTER TABLE IF EXISTS public.transacciones
      ADD CONSTRAINT transacciones_id_ejecutivo_fkey FOREIGN KEY (id_ejecutivo)
      REFERENCES public.ejecutivos (id_ejecutivo) MATCH SIMPLE
      ON UPDATE NO ACTION
      ON DELETE NO ACTION;
  
  END;