BEGIN TRANSACTION
DECLARE @check AS INT
SET @check = 0
SELECT @check = COUNT(PD.ProductId)
FROM Product PD
INNER JOIN Delivery_order DVO
ON PD.ProductId = DVO.ProductId
INNER JOIN Delivery_order_detail DOD
ON DVO.ProductId = DOD.ProductId
WHERE PD.ProductId = 'รหัสสินค้าที่ต้องการลบ'
IF (@check = 0 )
BEGIN
DELETE Product
WHERE ProductId = 'รหัสสินค้าที่ต้องการลบ'
END
IF @@ERROR > 0
BEGIN
ROLLBACK TRANSACTION
END
COMMIT TRANSACTION
BEGIN TRANSACTION
DECLARE @check AS INT
SET @check = 0
SELECT @check = COUNT(pd.pro_code)
FROM product pd
INNER JOIN delivery_order_detail do_dt
ON pd.pro_code = do_dt.pro_code
WHERE pd.pro_code = 'P0018'
SELECT @check = COUNT(pd.pro_code)
FROM product pd
INNER JOIN manufacture_detail m_dt
ON pd.pro_code = m_dt.pro_code
WHERE pd.pro_code = 'P0018'
IF (@check = 0 )
BEGIN
DELETE product
WHERE pro_code = 'P0018'
END
IF @@ERROR > 0
BEGIN
ROLLBACK TRANSACTION
END
COMMIT TRANSACTION
DECLARE @IsExists int = 0;
DECLARE @Fuck varchar(8);
IF EXISTS(SELECT 'FuckMom' FROM glacc WHERE RTRIM(accnum) = '1000-00')
SET @IsExists = 1
ELSE
IF EXISTS(SELECT 'FuckSon1' FROM glbal WHERE RTRIM(accnum) = '1410-01')
SET @IsExists = 2
ELSE
IF EXISTS(SELECT 'FuckSon2' FROM glbud WHERE RTRIM(accnum) = '11-05-01-03')
SET @IsExists = 3
ELSE
SET @Fuck = 'Fuck Forever and Never Die'
IF @IsExists > 0
SELECT @IsExists
ELSE
SELECT @Fuck