domingo, 16 de septiembre de 2007

Sentencias DML

INSERCION DE AGENCIAS
INSERT INTO Agencias (cod_agencia,nombre,ubicacion,bodega) VALUES('SPS001','Sucursal 3ra. Avenida','San Pedro Sula',default);
....

INSERCION DE CATEGORIAS
INSERT INTO categorias (cod_categoria,categoria) VALUES(1,'Ropa infantil');
.....
INSERCION DE MARCAS
INSERT INTO Marcas (cod_marca,Marca) VALUES(1,'Perry Ellis');
INSERT INTO Marcas (cod_marca,Marca) VALUES(30,'LoveHome');
.....
INSERCION DE PRODUCTOS
INSERT INTO Productos (id_prod,descripcion, isv,consumo_sem,precio_fijo,precio_desc,precio_mayor,unidad_venta,existencia_max,existencia_min,cod_marca,cod_categoria,imagen) VALUES('CA400453','Camisa manga corta','N',100,499.0,380.0,380.0,'unidad',200,1,1,3,NULL);
.....

Sentencias DDL

create table Agencias (
cod_agencia varchar(20) not null,
nombre varchar(30) not null,
ubicacion varchar(50) not null,
bodega char(1) not null default 'N',
primary key(cod_agencia),
);
create table Usuarios (
usuario varchar(30) not null,
clave varchar(30) not null,
cod_agencia varchar(20) not null,
primary key(usuario),
);
Alter table Usuarios add Agencias_FK foreign key(cod_agencia) references Agencias(cod_agencia) on update cascade;
create table Marcas (
Cod_marca integer not null;
Marca varchar(40) not null,
primary key(Cod_marca),
);
create table categorias (
cod_categoria integer not null,
categoria varchar(30) not null,
primary key(cod_categoria),
);
create table Productos (
id_prod varchar(20) not null,
descripcion varchar(40) not null,
isv char(1) not null,
consumo_sem integer,
precio_fijo double not null,
precio_desc double not null,
precio_mayor double not null,
unidad_venta varchar(20) ,
existencia_max integer ,
existencia_min integer ,
cod_marca integer not null,
cod_categoria integer not null,
primary key(id_prod),
);
Alter table Productos add Marcas foreign key(cod_marca) references Marcas(cod_marca) on update cascade;
Alter table Productos add categorias foreign key(cod_categoria) references categorias(cod_categoria) on update cascade;
create table Factura (
id_doc integer not null,
cliente varchar(30),
cod_agencia varchar(20) not null,
fecha date not null;
primary key(id_doc),
);
Alter table Factura add Agencias foreign key(cod_agencia) references Agencias(cod_agencia) on update cascade;
create table proveedores (
cod_proveedor varchar(20) not null,
nombre varchar(40) not null,
direccion varchar(60),
telefono varchar(12),
primary key(cod_proveedor ),
);
create table Compra (
id_doc integer not null,
cod_agencia varchar(20) not null,
fecha date not null;
cod_proveedor varchar(20);
primary key(id_doc),
);
Alter table Compra add Agencias foreign key(cod_agencia) references Agencias(cod_agencia) on update cascade;
Alter table Compra add proveedores foreign key(cod_proveedor) references proveedores(cod_proveedor) on update cascade;
create table Devolucion (
id_doc integer not null,
cod_agencia varchar(20) not null,
factura_id integer not null,
fecha date not null,
primary key(id_doc),
);
Alter table Devolucion add Agencias foreign key(cod_agencia) references Agencias(cod_agencia) on update cascade;
Alter table Devolucion add Factura foreign key(factura_id) references Factura(id_doc) on update cascade;
create table traslado (
id_doc integer not null,
cod_agencia varchar(20) not null,
agencia_destino varchar(20) not null,
fecha_envio date not null,
fecha_llegada date default '0000-00-00',
primary key(id_doc),
);
Alter table traslado add Agencias foreign key(cod_agencia) references Agencias(cod_agencia) on update cascade;
alter table traslado add Agencias2 foreign key(agencia_destino) references Agencias(cod_agencia) on update cascade;
create table vende (
id_doc integer not null,
id_prod varchar(20) not null,
cantidad integer not null,
primary key(id_doc,id_prod),
);
Alter table vende add Productos foreign key(id_prod) references Productos(id_prod) on update cascade;
Alter table vende add Factura foreign key(id_doc) references Factura(id_doc) on update cascade;
create table compra_de (
id_doc integer not null,
id_prod varchar(20) not null,
cantidad integer not null,
primary key(id_doc, id_prod),
);
alter table compra_de add Compra foreign key(id_doc) references Compra(id_doc) on update cascade;
alter table compra_de add Productos foreign key(id_prod) references Productos(id_prod) on update cascade;
create table es_devuelto (
id_doc integer not null,
id_prod varchar(20) not null,
cantidad integer not null,
primary key(id_doc,id_prod),
);
Alter table es_devuelto add Devolucion foreign key(id_doc) references Devolucion(id_doc) on update cascade;
Alter table es_devuelto add Productos foreign key(id_prod) references Productos(id_prod) on update cascade;

create table es_trasladado (
id_doc integer not null,
id_prod varchar(20) not null,
cantidad integer not null,
primary key(id_doc,id_prod),
);

Alter table es_trasladado add Productos foreign key(id_prod) references Productos(id_prod) on update cascade;
Alter table es_trasladado add traslado foreign key(id_doc) references traslado(id_doc) on update cascade;
create table kardex (
id_prod integer not null,
num integer not null,
entrada integer not null,
salida integer not null,
existencia integer not null,
debe double not null,
haber double not null,
saldo double not null,
costo_prom double not null,
unitario double not null,
cod_agencia varchar(20) not null,
id_doc_factura integer,
id_doc_devolucion integer,
id_doc_traslado integer,
id_doc_compra integer,
primary key(id_prod, num),
)
Alter table kardex add Productos foreign key(id_prod) references Productos(id_prod) on update cascade;
Alter table kardex add Agencias_FK_kardex foreign key(cod_agencia) references Agencias(cod_agencia) on update cascade;
Alter table kardex add traslado foreign key(id_doc_traslado) references traslado(id_doc) on update cascade;
Alter table kardex add Compra foreign key(id_doc_compra) references Compra(id_doc) on update cascade;
Alter table kardex add Factura foreign key(id_doc_factura) references Factura(id_doc) on update cascade;
Alter table kardex add Devolucion foreign key(id_doc_devolucion) references Devolucion(id_doc) on update cascade;

Modelo ER

MODELO ER

AGENCIAS (cod_agencia, nombre, ubicacion, bodega)
USUARIOS (usuario, clave, cod_agencia)
MARCAS (cod_marca, marca)
CATEGORIAS (cod_categoria, categoría)
PRODUCTOS (id_prod, descripción, isv, consumo_sem, precio_fijo, precio_desc, precio_mayor, unidad_venta, exitencia_max, existencia_min, cod_marca, cod_categoria, imagen)
FACTURA (id_doc, cliente, cod_agencia, fecha)
PROVEEDORES (cod_proveedor, nombre, dirección, teléfono)
COMPRA (id_doc, cod_agencia, fecha, cod_proveedor)
DEVOLUCION (id_doc, cod_agencia, factura_id, fecha)
TRASLADO (id_doc, cod_agencia, agencia_destino, fecha_envio, fecha_llegada)
VENDE (id_doc, id_prod, cantidad)
COMPRA_DE (id_doc, id_prod, cantidad)
ES_DEVUELTO (id_doc, id_prod, cantidad)
ES_TRASLADADO (id_doc, id_prod, cantidad)
KARDEX ( id_prod, num, entrada, salida, existencia, debe, haber, saldo, costo_prom, unitario, cod_agencia, id_doc_factura, id_doc_devolucion, id_doc_traslado, id_doc_compra)

lunes, 23 de julio de 2007

Proyecto

Hemos en conjunto con Elmer Manuel Ferrera y su servidor, Javier Montoya, crear el proyecto de Teoria de Base de Datos con el lenguaje Powerscript (Sybase Powerbuilder).