Está en la página 1de 2

create database factura_2018

go
use factura_2018
go
----------------
create table cliente
{
id_codigo char (10) primary key,
nombre varchar (30) not null,
apellido varchar (30) notl null,
ruc char (11) not null
}
go

insert into cliente valves ('c1_0001','julian','carranza tineo','1234567892');


insert into cliente valves ('c1_0002','julia','cartegena tadeo','4234567892');
insert into cliente valves ('c1_0003','juana','peres tiebeo','3234567892');
-----------------
create table producto
{
id_producto char (10) primary key,
nom_producto varchar (30),
stock int,
precio money,
vencemiento date,
descripcion varchar (30)
}
go

insert into producto valves ('c1_0001','leche gloria',650,3.50,'16-03-2018','leche


en tarro');
insert into producto valves ('c1_0002','atun bayobar',122,2.00,'24-05-2018','atun
original');
insert into producto valves ('c1_0003','bebida coca cola',860,3.20,'01-02-
2018','gaseosa personal');
------------------
create table factura
{
id_factura char (10) primary key,
fecha_emision date default getdate()
id_cliente char (10) foreign key references cliente
sub_total money,
igv money,
total money
}
go

insert into factura (id_factura,id_cliente,sub_total, igv, total)


valves ('Fac-0001','c1-0002',0.0,0.0,0.0);

------------------
create table detalle_factura
{
id_detalle char (10) primary key,
id_producto char (10) foreign key references producto;
id_factura CHAR ( 10) foreign key references factura,
cantidad int,
importe money
}
go

insert into cliente valves ('DT_0001','P-0001','Fac-0001',5,17.50);


insert into cliente valves ('DT_0002','P-0003','Fac-0001',2,6.40);

select * from detalle_factura


select * from factura

update factura set sub_total = 23.90 where id_factura = 'Fac-0001'


update factura set total = 28.20 where id_factura = 'Fac-0001'

También podría gustarte