0% found this document useful (0 votes)
51 views4 pages

Los Triggers Estan Hechos para Que Se Elimine de Las Tablas Padres e Hijas Las Tuplas Que No Se Desee: Categoria

The document discusses triggers and stored procedures created for a pharmacy system database. Triggers are used to delete related records from child tables when records are deleted from parent tables, such as deleting product records when a category is deleted. Stored procedures are created to delete, search for, and modify specific records in different tables, including clients, products, providers, and categories. A trigger is also created to update product stock quantities when an order/sale is made.

Uploaded by

David Pacheco
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views4 pages

Los Triggers Estan Hechos para Que Se Elimine de Las Tablas Padres e Hijas Las Tuplas Que No Se Desee: Categoria

The document discusses triggers and stored procedures created for a pharmacy system database. Triggers are used to delete related records from child tables when records are deleted from parent tables, such as deleting product records when a category is deleted. Stored procedures are created to delete, search for, and modify specific records in different tables, including clients, products, providers, and categories. A trigger is also created to update product stock quantities when an order/sale is made.

Uploaded by

David Pacheco
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

TRIGGERS

Los triggers estan hechos para que se elimine de las tablas padres e
hijas las tuplas que no se desee:

Categoria

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER trigger [dbo].[eliminar_categoria]
on [SistemaFarmacia].[dbo].[categoria]
INSTEAD OF delete
as
delete from dbo.producto
where producto.codcat = (SELECT cod_cat FROM DELETED);

Cliente

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER trigger [dbo].[eliminar_cliente]
on [SistemaFarmacia].[dbo].[cliente]
INSTEAD OF delete
as
delete from dbo.cliente_venta
where cliente_venta.id_cli = (SELECT CEDULA FROM DELETED);

Producto

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER trigger [dbo].[eliminar_producto]
on [SistemaFarmacia].[dbo].[producto]
INSTEAD OF delete
as
delete from dbo.producto_venta
where producto_venta.codigo_prod = (SELECT codProd FROM DELETED);

Proveedor

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER trigger [dbo].[eliminar_proveedor]
on [SistemaFarmacia].[dbo].[proveedor]

INSTEAD OF delete
as
delete from dbo.producto
where producto.codprov = (SELECT codigo FROM DELETED);

Trigger creado para reducir ka cantidad de productos existentes o en


stock, si se realiza un pedido
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER trigger [dbo].[actualizar_stock]
on [SistemaFarmacia].[dbo].[venta]
AFTER insert
as
update [SistemaFarmacia].[producto] set stock = stock - (SELECT
cantidad FROM #INSERTED)
where (SELECT codproducto FROM #INSERTED) = codProd;

Procedimientos
Procediientos creados para borrar de una tabla elementos no deseados

Cliente

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[BorrarCliente]
(
@Param1 nchar(10)
)
AS
SET NOCOUNT OFF;
DELETE FROM [dbo].[cliente] WHERE (([CEDULA] = @Param1))

Producto

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[EliminarProducto]
(
@Param1 varchar(30)
)
AS
SET NOCOUNT OFF;
DELETE FROM [dbo].[producto] WHERE ([codProd] = @Param1)

Proveedor

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[EliminarProveedor]
(
@Param5 varchar(30)
)
AS
SET NOCOUNT OFF;
DELETE FROM [dbo].[proveedor] WHERE (codigo=@Param5)

Categoria

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[EliminarCategoria]
(
@Parm1 varchar(30)
)
AS
SET NOCOUNT OFF;
DELETE FROM [dbo].[categoria] WHERE ([cod_cat] = @Parm1)

Procedimientos creados para buscar

Cliente

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[BuscarCliente]
(
@Param1 nchar(10)
)
AS
SET NOCOUNT ON;
SELECT CEDULA, NOMBRE, TELEFONO, DIRECCION FROM dbo.cliente where
CEDULA=@Param1

Producto

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON

go
ALTER PROCEDURE [dbo].[BuscarProducto]
(
@Param1 varchar(30)
)
AS
SET NOCOUNT ON;
SELECT codProd, nom_prod, precio_actual, stock, codprov, codcat FROM
dbo.producto where (codProd=@Param1)

Proveedor

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[BuscarProveedor]
(
@Param5 varchar(30)
)
AS
SET NOCOUNT ON;
SELECT nomP, Ruc, telefono, direccionP, codigo FROM dbo.proveedor where
(codigo=@Param5)

Categoria

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[BuscarCategoria]
(
@Parm1 varchar(30)
)
AS
SET NOCOUNT ON;
SELECT cod_cat, nombre, descripcion FROM dbo.categoria where
(cod_cat=@Parm1)
Procediientos para modificar
Procediientos para insertar

You might also like