0
I tried to create several tables in SQL but 2 of them gave the same error:
"Msg 1767, Level 16, State 0, Line 72 Foreign key 'Fk__movimento__codem__3118447e' References invalid table "emprestimo".
And
"Msg 1750, Level 16, State 0, Line 72.Could not create Constraint or index. See Previous errors."
These are the two tables:
create table emprestimo(
codemprestimo smallint,
dataemprestimo varchar(10),
valoremprestimo float,
taxajuro float,
numeroemprestimo smallint,
observacoes varchar(100),
codagencia smallint,
foreign key(codagencia) references agencia(codagencia)
on update cascade
on delete cascade,
codconta smallint,
foreign key(codconta) references conta(codconta)
on update cascade
on delete cascade,
primary key(codemprestimo));
create table movimentoconta(
codmovconta smallint,
datamov varchar(10),
valormov float,
codtipomov smallint,
foreign key(codtipomov) references tipomovimento(codtipomov)
on update cascade
on delete cascade,
codemprestimo smallint,
foreign key (codemprestimo) references emprestimo(codemprestimo)
on update cascade
on delete cascade,
codclienteconta smallint,
foreign key(codclienteconta) references clienteconta(codclienteconta)
on update cascade
on delete cascade,
primary key(codmovconta));
agencia
already exists? The fieldcodagencia
the tableagencia
, isprimary key
? 2. You need to create the fieldcodemprestimo
, on the tablemovimentoconta
so that it is referenced, andprimary key
. All this if you really want to put theforeign key
– David
the type table exists ? What is its PK ? I don’t know the syllabus but also make columns and indices separately
– Motta