Hi, I'm trying to create these tables in SQL
create table Clientes(
Tdoc varchar (10),
Ndoc int,
Nombre varchar(30),
Apellido varchar(30),
constraint p_key primary key(Tdoc,Ndoc)
)
create table Vendedor(
Tdoc varchar (10),
Ndoc int,
Nombre varchar(30),
Apellido varchar(30),
constraint p_key_ve primary key(Tdoc,Ndoc)
)
create table Venta( tdoc_vend varchar (10),
ndoc_vend int,
tdoc_cli varchar (10),
ndoc_cli int,
nro_fac int,
fecha date,
tipo_pago int,
constraint venta_key primary key (tdoc_vend, ndoc_vend, tdoc_cli, ndoc_cli, nro_fac),
constraint t_doc foreign key (tdoc_vend, ndoc_vend) references Vendedor (Tdoc, Ndoc),
constraint cli foreign key (tdoc_cli, ndoc_cli) references Clientes (Tdoc, Ndoc)
)
create table Producto ( id int primary key,
descripcion varchar (20),
precio float)
create table TPago ( id int primary key,
descripcion varchar (20))
create table Detalle_venta (nro_fact int,
id_prod int,
cantidad int,
constraint keyDv primary key (nro_fact, id_prod),
constraint nrofac foreign key (nro_fact) references Venta(nro_fac),
constraint idpro foreign key (id_prod) references Producto(id)
)
The problem is when I try to create the last table, where I get the following error
Mens. 1776, Nivel 16, Estado 0, Línea 880
There are no primary or candidate keys in the referenced table 'Venta' that match the referencing column list in the foreign key 'nrofac'.
Mens. 1750, Nivel 16, Estado 1, Línea 880
Could not create constraint or index. See previous errors.