Error with another bank’s Foreign key

Asked

Viewed 60 times

2

I’m trying to put Foreign key related to tables from another database (I’m performing tests and sometimes I need to delete the main database).

However it presents the following errors:

Message 1763, Level 16, Status 0, Line 93 No support for foreign key references in all databases. Key foreign 'municipios.dbo.State'. Message 1750, Level 16, State 1, Line 93 Could not create constraint or index. See the previous errors.

Status table:

CREATE TABLE Estado (
    CodigoUf INT          NOT NULL,
    Nome     VARCHAR (50) NOT NULL,
    Uf       CHAR    (2)  NOT NULL,
    Regiao   INT          NOT NULL,
    PRIMARY KEY (CodigoUf),

constraint fk_Uf_Regiao foreign key (Regiao) references Regiao(Id)
);

Table I am doing to Foreign:

create table Clientes(
ID_int          int identity,
ID              AS RIGHT('000000' + CAST(ID_int AS VARCHAR(6)), 6) PERSISTED,
Loja            varchar(4),
Tipo            varchar(4),
CNPJ_CPF        varchar(14),
IE              varchar(14),
Nome            varchar(60),
nome_fantasia   varchar(60),
E_mail          varchar(60),
Telefone        varchar(20),
Endereco        varchar(30),
Bairro          varchar(30),
Cod_Mun         varchar(7),
Municipio       varchar(30),
Uf              int,
CEP             varchar(8),
Bloqueado       varchar(3) default 'NAO',
Forma_pagamento int,
data_cadastro   datetime,
ult_compra      datetime,
primeira_compra datetime,
Media_Atrasos   int,
Tabela_preco    varchar(3),
Tp_entrega      varchar(1),
grp_vendas      varchar(6),

constraint pk_Clientes primary key (CNPJ_CPF),
constraint fk_Clientes_UF foreign key (uf) references [municipios].[dbo].[Estado](CodigoUf) ON DELETE NO ACTION ON UPDATE CASCADE,
constraint fk_Clientes_Mun foreign key (Cod_Mun) references [municipios].[dbo].[Municipio](Cod_Mun) ON DELETE NO ACTION ON UPDATE CASCADE,
constraint fk_Clientes_Tabela foreign key (tabela_preco) references tabela_precos(id),
constraint fk_Clientes_grp foreign key (grp_vendas) references grupo_vendas(id)
)
go

1 answer

4


Marcos, the English text of the 1763 error message does not make clear what the cause is:
"No support for foreign key references in all databases"

In "all databases"?!

-- But here is the original text of the 1763 error message:
"Cross-database Foreign key References are not supported. Foreign key ?%. *ls'"

Now it’s clear what the reason for the mistake is, right? In short, foreign key references between databases are not possible.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.