Initial commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Tables].[trg_insert_product_outflow_records]', 'TR') IS NOT NULL
|
||||
DROP TRIGGER [Tables].[trg_insert_product_outflow_records];
|
||||
GO
|
||||
CREATE TRIGGER [Tables].[trg_insert_product_outflow_records] ON [Tables].[product_outflow_records] AFTER INSERT
|
||||
AS
|
||||
IF NOT EXISTS(
|
||||
SELECT *
|
||||
FROM [inserted] AS [i]
|
||||
JOIN [Tables].[price_history_records] AS [phr]
|
||||
ON [phr].[product_id] = [i].[product_id]
|
||||
)
|
||||
BEGIN
|
||||
ROLLBACK TRANSACTION;
|
||||
RETURN;
|
||||
END
|
||||
DECLARE @barcode_attribute_id AS INT;
|
||||
SET @barcode_attribute_id = (
|
||||
SELECT [id]
|
||||
FROM [Tables].[attributes]
|
||||
WHERE [name] = 'Barcode'
|
||||
);
|
||||
DECLARE @stocks AS INT;
|
||||
SET @stocks = (
|
||||
SELECT [Functions].[product_with_barcode_stock]([barcode])
|
||||
FROM [inserted]
|
||||
);
|
||||
IF @stocks < 0
|
||||
BEGIN
|
||||
ROLLBACK TRANSACTION;
|
||||
RETURN;
|
||||
END
|
||||
GO
|
||||
@@ -0,0 +1,22 @@
|
||||
USE [Database]
|
||||
|
||||
IF OBJECT_ID('[Tables].[trg_insert_product_values]', 'TR') IS NOT NULL
|
||||
DROP TRIGGER [Tables].[trg_insert_product_values];
|
||||
GO
|
||||
CREATE TRIGGER [Tables].[trg_insert_product_values] ON [Tables].[product_values] AFTER INSERT
|
||||
AS
|
||||
IF EXISTS(
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT [i].[value], COUNT(*) AS [count]
|
||||
FROM [Tables].[product_values] AS [PV]
|
||||
JOIN [inserted] AS [i]
|
||||
ON [i].[id] = [PV].[product_id]
|
||||
) AS [values]
|
||||
WHERE [count] > 1
|
||||
)
|
||||
BEGIN
|
||||
ROLLBACK TRANSACTION;
|
||||
RETURN;
|
||||
END
|
||||
GO
|
||||
Reference in New Issue
Block a user