CREATE TABLE IF NOT EXISTS public.nfs_nota_fiscal_cliente_destino ( filial_nota integer NOT NULL, nota integer NOT NULL, serie character varying(6) NOT NULL, cliente_destino integer NOT NULL, sequencia_endereco integer NOT NULL, CONSTRAINT pk_nfs_nota_fiscal_cliente_destino PRIMARY KEY (filial_nota, nota, serie), CONSTRAINT fk_nfs_nota_fiscal_cliente_destino_nota FOREIGN KEY (filial_nota, nota, serie) REFERENCES public.nfs_nota_fiscal (filial_nota, nota, serie) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE RESTRICT, CONSTRAINT fk_nfs_nota_fiscal_cliente_destino_cliente FOREIGN KEY (filial_nota, cliente_destino) REFERENCES public.cli_cliente (filial, codigo) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE RESTRICT, CONSTRAINT fk_nfs_nota_fiscal_cliente_destino_endereco FOREIGN KEY (filial_nota, cliente_destino, sequencia_endereco) REFERENCES public.cli_endereco (filial, cliente, sequencia) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE RESTRICT ); CREATE TABLE IF NOT EXISTS public.vnd_orcamento_cliente_destino ( filial_orc integer NOT NULL, orcamento integer NOT NULL, cliente_destino integer NOT NULL, sequencia_endereco integer NOT NULL, CONSTRAINT pk_vnd_orcamento_cliente_destino PRIMARY KEY (filial_orc, orcamento), CONSTRAINT fk_vnd_orcamento_cliente_destino_orcamento FOREIGN KEY (filial_orc, orcamento) REFERENCES public.vnd_orcamento (filial_orc, orcamento) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE RESTRICT, CONSTRAINT fk_vnd_orcamento_cliente_destino_cliente FOREIGN KEY (filial_orc, cliente_destino) REFERENCES public.cli_cliente (filial, codigo) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE RESTRICT, CONSTRAINT fk_vnd_orcamento_cliente_destino_endereco FOREIGN KEY (filial_orc, cliente_destino, sequencia_endereco) REFERENCES public.cli_endereco (filial, cliente, sequencia) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE RESTRICT );