· 8 years ago · Aug 15, 2018, 04:42 AM
1-- Database: "SistemaProduccion"
2
3-- DROP DATABASE "SistemaProduccion";
4drop database if exists SistemaProduccion;
5
6drop table if exists Productos
7drop table if exists Insumos
8drop table if exists Areas
9drop table if exists Empleados
10drop table if exists ValoresIniciales
11drop table if exists InicioSesion
12drop table if exists CompraXInsumo
13drop table if exists Nomina
14drop table if exists VentaXProducto
15
16CREATE DATABASE "SistemaProduccion"
17 WITH OWNER = postgres
18 ENCODING = 'UTF8'
19 TABLESPACE = pg_default
20 LC_COLLATE = 'es_CR.UTF-8'
21 LC_CTYPE = 'es_CR.UTF-8'
22 CONNECTION LIMIT = -1;
23
24create table Insumos (
25 Id serial not null,
26 Nombre char(25) not null,
27 CONSTRAINT PK_INSUMOS PRIMARY KEY (Id),
28 unique(Nombre)
29);
30
31create table Productos(
32 Id serial not null,
33 Nombre char(25) not null,
34 Precio int not null,
35 ImpuestoAplicado float not null,
36 CONSTRAINT PK_PRODUCTOS PRIMARY KEY (Id),
37 UNIQUE (Nombre)
38);
39
40create table Areas(
41 Id serial not null,
42 Nombre char(25) not null,
43 Dimension float not null,
44 ProductoProducido int not null REFERENCES Productos(Id),
45 Estado boolean not null,
46 CONSTRAINT PK_AREAS PRIMARY KEY (Id),
47 UNIQUE(Nombre)
48);
49
50create table Empleados(
51 Cedula int not null,
52 Nombre char(25) not null,
53 Apellidos char(30) not null,
54 Labor char(25) not null,
55 SalarioMensual int not null,
56 SalarioCarga float not null,
57 Estado boolean not null,
58 CONSTRAINT PK_EMPLEADOS PRIMARY KEY (Cedula)
59);
60
61create table ValoresIniciales(
62 Nombre char(25) not null,
63 Telefono char(10) not null,
64 CedulaJuridica char(15) not null,
65 NumeroSecuencial serial not null
66);
67
68create table InicioSesion(
69 Usuario char(25) not null,
70 Contrasenia char(25) not null
71);
72
73create table CompraXInsumo(
74 IdInsumo int not null REFERENCES Insumos(Id),
75 NumFactura int not null,
76 Cantidad int not null,
77 PrecioUnitario int not null,
78 ImpuestoUnitario float not null,
79 NombreProveedor char(25) not null,
80 Fecha date not null
81);
82
83create table Nomina(
84 Id int not null,
85 Mes int not null,
86 Anio int not null,
87 CedulaEmpleado int not null references Empleados(Cedula),
88 NombreEmpleado char(25) not null,
89 LaborEmpleado char(25) not null,
90 SalarioMensual int not null,
91 SalarioCarga float not null
92);
93create table VentaXProducto(
94 Id serial not null,
95 IdProducto int not null REFERENCES Productos(Id),
96 Cantidad int not null,
97 Area char(25) not null,
98 PrecioUnitario int not null,
99 ImpuestoUnitario float not null,
100 NombreCliente char(25) not null,
101 Fecha date not null,
102 Local char(25) not null,
103 CedJuridica char(15) not null,
104 Telefono char(10) not null
105);
106
107
108insert into Insumos (Nombre) values ('Clavo');
109insert into Insumos (nombre) values ('Pegamento');
110select * from Insumos;
111
112insert into Productos (Nombre,Precio,ImpuestoAplicado) values('Atun',2000,0.13);
113insert into Productos (Nombre,Precio,ImpuestoAplicado) values('Garbanzos',2000,0.13);
114insert into Productos (Nombre,Precio,ImpuestoAplicado) values('Aceite',2000,0.13);
115select * from Productos;
116
117insert into Areas (Nombre,Dimension,ProductoProducido,Estado) values ('Las Mantas',500,2,'1');
118select * from Areas;
119
120insert into Empleados values(702550708,'Luis','Araya Aragon','Cargador',10000,10000*(1.50),'1');
121insert into Empleados values(602210128,'Mario','Altamirano Aragon','Inspector',20000,20000*(1.50),'1');
122select * from Empleados;
123
124insert into ValoresIniciales values('Megasuper','27184576','3024150012');
125insert into ValoresIniciales values('PalÃ','27189556','3024150021');
126select * from ValoresIniciales;
127
128Insert into InicioSesion values('operativo','operativo');
129Insert into InicioSesion values('administrador','administrador');
130select * from InicioSesion;
131
132Insert into CompraXInsumo values(1,1,5,2500,0.13,'WallMart','14/8/2018');
133Insert into CompraXInsumo values(2,1,10,2000,0.13,'WallMart','14/8/2018');
134Select * from CompraXInsumo
135
136Insert into Nomina values(1,8,2018,702550708,'Luis','Cargador',10000,15000);
137Insert into Nomina values(1,8,2018,602210128,'Mario','Inspector',20000,35000);
138select * from Nomina
139
140insert into VentaXProducto (IdProducto,Cantidad,Area,PrecioUnitario,ImpuestoUnitario,NombreCliente,Fecha,NombreLocal,CedJuridica,Telefono)
141values(1,10,'Las Mantas',2000,0.13,'Carlos','14/8/2018','PalÃ','3024150021','27189556');
142select * from VentaXProducto