1. T_ORDER
For Insert: sp_order_i
For Update: sp_order_u
For Delete: sp_order_d
2. T_ORDER_DETAIL
FOR Insert: sp_order_detail_i
For Update: sp_order_detail_u
For Delete: sp_order_detail_d
For Insert: sp_order_i
IF
EXISTS (
SELECT
*
FROM sysobjects
WHERE type
=
'
P
'
AND name
=
'
sp_order_i
')
BEGIN
DROP Procedure sp_order_i
END
GO
CREATE Procedure sp_order_i
(
@p_order_id INT OUTPUT,
@p_order_date DATETIME,
@p_supplier VARCHAR( 50),
@p_created_by VARCHAR( 50),
@p_created_on DATETIME,
@p_last_updated_by VARCHAR( 50),
@p_last_updated_on DATETIME,
@p_transaction_no CHAR( 36)
)
AS
INSERT [ dbo ]. [ T_ORDER ]
( [ ORDER_DATE ]
, [ SUPPLIER ]
, [ CREATED_BY ]
, [ CREATED_ON ]
, [ LAST_UPDATED_BY ]
, [ LAST_UPDATED_ON ]
, [ TRANSACTION_NO ])
VALUES
( @p_order_date ,
@p_supplier ,
@p_created_by ,
@p_created_on ,
@p_last_updated_by ,
@p_last_updated_on ,
@p_transaction_no)
SET @p_order_id = SCOPE_IDENTITY()
IF @@ROWCOUNT = 0
BEGIN
RAISERROR ( ' Version conflicts! ', 10, 1)
END
GO
BEGIN
DROP Procedure sp_order_i
END
GO
CREATE Procedure sp_order_i
(
@p_order_id INT OUTPUT,
@p_order_date DATETIME,
@p_supplier VARCHAR( 50),
@p_created_by VARCHAR( 50),
@p_created_on DATETIME,
@p_last_updated_by VARCHAR( 50),
@p_last_updated_on DATETIME,
@p_transaction_no CHAR( 36)
)
AS
INSERT [ dbo ]. [ T_ORDER ]
( [ ORDER_DATE ]
, [ SUPPLIER ]
, [ CREATED_BY ]
, [ CREATED_ON ]
, [ LAST_UPDATED_BY ]
, [ LAST_UPDATED_ON ]
, [ TRANSACTION_NO ])
VALUES
( @p_order_date ,
@p_supplier ,
@p_created_by ,
@p_created_on ,
@p_last_updated_by ,
@p_last_updated_on ,
@p_transaction_no)
SET @p_order_id = SCOPE_IDENTITY()
IF @@ROWCOUNT = 0
BEGIN
RAISERROR ( ' Version conflicts! ', 10, 1)
END
GO
For Update: sp_order_u
IF
EXISTS (
SELECT
*
FROM sysobjects
WHERE type
=
'
P
'
AND name
=
'
sp_order_u
')
BEGIN
DROP Procedure sp_order_u
END
GO
CREATE Procedure sp_order_u
(
@o_order_id INT,
@p_order_date DATETIME,
@p_supplier VARCHAR( 50),
@p_last_updated_by VARCHAR( 50),
@p_last_updated_on DATETIME,
@p_transaction_no CHAR( 36),
@o_version_no TIMESTAMP
)
AS
UPDATE [ dbo ]. [ T_ORDER ]
SET [ ORDER_DATE ] = @p_order_date
, [ SUPPLIER ] = @p_supplier
, [ LAST_UPDATED_BY ] = @p_last_updated_by
, [ LAST_UPDATED_ON ] = @p_last_updated_on
, [ TRANSACTION_NO ] = @p_transaction_no
WHERE ORDER_ID = @o_order_id
AND VERSION_NO = @o_version_no
IF @@ROWCOUNT = 0
BEGIN
RAISERROR ( ' Version conflicts! ', 10, 1)
END
GO
BEGIN
DROP Procedure sp_order_u
END
GO
CREATE Procedure sp_order_u
(
@o_order_id INT,
@p_order_date DATETIME,
@p_supplier VARCHAR( 50),
@p_last_updated_by VARCHAR( 50),
@p_last_updated_on DATETIME,
@p_transaction_no CHAR( 36),
@o_version_no TIMESTAMP
)
AS
UPDATE [ dbo ]. [ T_ORDER ]
SET [ ORDER_DATE ] = @p_order_date
, [ SUPPLIER ] = @p_supplier
, [ LAST_UPDATED_BY ] = @p_last_updated_by
, [ LAST_UPDATED_ON ] = @p_last_updated_on
, [ TRANSACTION_NO ] = @p_transaction_no
WHERE ORDER_ID = @o_order_id
AND VERSION_NO = @o_version_no
IF @@ROWCOUNT = 0
BEGIN
RAISERROR ( ' Version conflicts! ', 10, 1)
END
GO
For Delete: sp_order_d
IF
EXISTS (
SELECT
*
FROM sysobjects
WHERE type
=
'
P
'
AND name
=
'
sp_order_d
')
BEGIN
DROP Procedure sp_order_d
END
GO
CREATE Procedure sp_order_d
(
@o_order_id INT,
@p_transaction_no CHAR( 36),
@o_version_no TIMESTAMP
)
AS
UPDATE dbo.T_ORDER
SET TRANSACTION_NO = @p_transaction_no ,
NEED_AUDIT = 0
WHERE ORDER_ID = @o_order_id
AND VERSION_NO = @o_version_no
IF @@ROWCOUNT = 0
BEGIN
RAISERROR ( ' Version conflicts! ', 10, 1)
END
DELETE dbo.T_ORDER
WHERE ORDER_ID = @o_order_id
GO
BEGIN
DROP Procedure sp_order_d
END
GO
CREATE Procedure sp_order_d
(
@o_order_id INT,
@p_transaction_no CHAR( 36),
@o_version_no TIMESTAMP
)
AS
UPDATE dbo.T_ORDER
SET TRANSACTION_NO = @p_transaction_no ,
NEED_AUDIT = 0
WHERE ORDER_ID = @o_order_id
AND VERSION_NO = @o_version_no
IF @@ROWCOUNT = 0
BEGIN
RAISERROR ( ' Version conflicts! ', 10, 1)
END
DELETE dbo.T_ORDER
WHERE ORDER_ID = @o_order_id
GO
2. T_ORDER_DETAIL
FOR Insert: sp_order_detail_i
IF
EXISTS (
SELECT
*
FROM sysobjects
WHERE type
=
'
P
'
AND name
=
'
sp_order_detail_i
')
BEGIN
DROP Procedure sp_order_detail_i
END
GO
CREATE Procedure sp_order_detail_i
(
@p_order_id INT,
@p_product_id INT,
@p_product_name VARCHAR( 50),
@p_unit_price MONEY,
@p_quantity INT,
@p_created_by VARCHAR( 50),
@p_created_on DATETIME,
@p_last_updated_by VARCHAR( 50),
@p_last_updated_on DATETIME,
@p_transaction_no CHAR( 36)
)
AS
INSERT INTO [ dbo ]. [ T_ORDER_DETAIL ]
( [ ORDER_ID ]
, [ PRODUCT_ID ]
, [ PRODUCT_NAME ]
, [ UNIT_PRICE ]
, [ QUANTITY ]
, [ CREATED_BY ]
, [ CREATED_ON ]
, [ LAST_UPDATED_BY ]
, [ LAST_UPDATED_ON ]
, [ TRANSACTION_NO ])
VALUES
( @p_order_id,
@p_product_id,
@p_product_name,
@p_unit_price,
@p_quantity,
@p_created_by ,
@p_created_on ,
@p_last_updated_by ,
@p_last_updated_on ,
@p_transaction_no)
IF @@ROWCOUNT = 0
BEGIN
RAISERROR ( ' Version conflicts! ', 10, 1)
END
GO
BEGIN
DROP Procedure sp_order_detail_i
END
GO
CREATE Procedure sp_order_detail_i
(
@p_order_id INT,
@p_product_id INT,
@p_product_name VARCHAR( 50),
@p_unit_price MONEY,
@p_quantity INT,
@p_created_by VARCHAR( 50),
@p_created_on DATETIME,
@p_last_updated_by VARCHAR( 50),
@p_last_updated_on DATETIME,
@p_transaction_no CHAR( 36)
)
AS
INSERT INTO [ dbo ]. [ T_ORDER_DETAIL ]
( [ ORDER_ID ]
, [ PRODUCT_ID ]
, [ PRODUCT_NAME ]
, [ UNIT_PRICE ]
, [ QUANTITY ]
, [ CREATED_BY ]
, [ CREATED_ON ]
, [ LAST_UPDATED_BY ]
, [ LAST_UPDATED_ON ]
, [ TRANSACTION_NO ])
VALUES
( @p_order_id,
@p_product_id,
@p_product_name,
@p_unit_price,
@p_quantity,
@p_created_by ,
@p_created_on ,
@p_last_updated_by ,
@p_last_updated_on ,
@p_transaction_no)
IF @@ROWCOUNT = 0
BEGIN
RAISERROR ( ' Version conflicts! ', 10, 1)
END
GO
For Update: sp_order_detail_u
IF
EXISTS (
SELECT
*
FROM sysobjects
WHERE type
=
'
P
'
AND name
=
'
sp_order_detail_u
')
BEGIN
DROP Procedure sp_order_detail_u
END
GO
CREATE Procedure sp_order_detail_u
(
@o_order_id INT,
@o_product_id INT,
@p_product_name VARCHAR( 50),
@p_unit_price MONEY,
@p_quantity INT,
@p_last_updated_by VARCHAR( 50),
@p_last_updated_on DATETIME,
@p_transaction_no CHAR( 36),
@o_version_no TIMESTAMP
)
AS
UPDATE [ dbo ]. [ T_ORDER_DETAIL ]
SET [ PRODUCT_NAME ] = @p_product_name
, [ UNIT_PRICE ] = @p_unit_price
, [ QUANTITY ] = @p_quantity
, [ LAST_UPDATED_BY ] = @p_last_updated_by
, [ LAST_UPDATED_ON ] = @p_last_updated_on
, [ TRANSACTION_NO ] = @p_transaction_no
WHERE ORDER_ID = @o_order_id
AND PRODUCT_ID = @o_product_id
AND VERSION_NO = @o_version_no
IF @@ROWCOUNT = 0
BEGIN
RAISERROR ( ' Version conflicts! ', 10, 1)
END
GO
BEGIN
DROP Procedure sp_order_detail_u
END
GO
CREATE Procedure sp_order_detail_u
(
@o_order_id INT,
@o_product_id INT,
@p_product_name VARCHAR( 50),
@p_unit_price MONEY,
@p_quantity INT,
@p_last_updated_by VARCHAR( 50),
@p_last_updated_on DATETIME,
@p_transaction_no CHAR( 36),
@o_version_no TIMESTAMP
)
AS
UPDATE [ dbo ]. [ T_ORDER_DETAIL ]
SET [ PRODUCT_NAME ] = @p_product_name
, [ UNIT_PRICE ] = @p_unit_price
, [ QUANTITY ] = @p_quantity
, [ LAST_UPDATED_BY ] = @p_last_updated_by
, [ LAST_UPDATED_ON ] = @p_last_updated_on
, [ TRANSACTION_NO ] = @p_transaction_no
WHERE ORDER_ID = @o_order_id
AND PRODUCT_ID = @o_product_id
AND VERSION_NO = @o_version_no
IF @@ROWCOUNT = 0
BEGIN
RAISERROR ( ' Version conflicts! ', 10, 1)
END
GO
For Delete: sp_order_detail_d
IF
EXISTS (
SELECT
*
FROM sysobjects
WHERE type
=
'
P
'
AND name
=
'
sp_order_detail_d
')
BEGIN
DROP Procedure sp_order_detail_d
END
GO
CREATE Procedure sp_order_detail_d
(
@o_order_id INT,
@o_product_id INT,
@p_transaction_no CHAR( 36),
@o_version_no TIMESTAMP
)
AS
UPDATE [ dbo ]. [ T_ORDER_DETAIL ]
SET TRANSACTION_NO = @p_transaction_no,
NEED_AUDIT = 0
WHERE ORDER_ID = @o_order_id
AND PRODUCT_ID = @o_product_id
AND VERSION_NO = @o_version_no
IF @@ROWCOUNT = 0
BEGIN
RAISERROR ( ' Version conflicts! ', 10, 1)
END
DELETE FROM [ dbo ]. [ T_ORDER_DETAIL ]
WHERE ORDER_ID = @o_order_id
AND PRODUCT_ID = @o_product_id
GO
BEGIN
DROP Procedure sp_order_detail_d
END
GO
CREATE Procedure sp_order_detail_d
(
@o_order_id INT,
@o_product_id INT,
@p_transaction_no CHAR( 36),
@o_version_no TIMESTAMP
)
AS
UPDATE [ dbo ]. [ T_ORDER_DETAIL ]
SET TRANSACTION_NO = @p_transaction_no,
NEED_AUDIT = 0
WHERE ORDER_ID = @o_order_id
AND PRODUCT_ID = @o_product_id
AND VERSION_NO = @o_version_no
IF @@ROWCOUNT = 0
BEGIN
RAISERROR ( ' Version conflicts! ', 10, 1)
END
DELETE FROM [ dbo ]. [ T_ORDER_DETAIL ]
WHERE ORDER_ID = @o_order_id
AND PRODUCT_ID = @o_product_id
GO
作者:蒋金楠
微信公众账号:大内老A
微博: www.weibo.com/artech
如果你想及时得到个人撰写文章以及著作的消息推送,或者想看看个人推荐的技术资料,可以扫描左边二维码(或者长按识别二维码)关注个人公众号(原来公众帐号 蒋金楠的自媒体将会停用)。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
微信公众账号:大内老A
微博: www.weibo.com/artech
如果你想及时得到个人撰写文章以及著作的消息推送,或者想看看个人推荐的技术资料,可以扫描左边二维码(或者长按识别二维码)关注个人公众号(原来公众帐号 蒋金楠的自媒体将会停用)。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。