create database
negocio
;
create table cliente (
id_cliente int identity(1,1),
Nombre varchar (50) not null,
Apellido varchar (50) not null,
Direccion varchar (100) not null,
Primary key (id_cliente)
);
create table producto (
id_producto int primary key identity(1,1),
Producto varchar (50) not null,
id_cliente int not null,
Precio_unidad DECIMAL(10, 2) not null,
Stock INT not null DEFAULT 0,
foreign key (id_cliente) REFERENCES cliente (id_cliente)
);
create table factura_resume (
id_factura int primary key identity(1,1),
id_cliente int not null,
Total_factura Decimal (10, 2) not null,
foreign key (id_cliente) REFERENCES cliente (id_cliente)
);
create table factura_detalle (
id_detalle int primary key identity(1,1),
id_factura int not null,
id_producto int not null,
Cantidad INT not null,
Precio_unidad DECIMAL(10, 2) not null,
Subtotal DECIMAL(10, 2) null,
foreign key (id_factura) references factura_resume (id_factura),
foreign key (id_producto) references producto (id_producto)
);