表A结构如下。
ID (PK), Name, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10,
created-user, created-date, modified-user, modified-date
表B结构如下。
ID, Table name, Name
插入数据时执行的步骤。
获取Java应用程序发送的数据并进行验证。已经编写了一个程序,它将生成如下输出。
Insert into Table A (Name, Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10)
Values (‘Mod1’, ‘ACB1’, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
在同一程序中,将执行插入语句。
已经编写了以下内容而不是Trigger。 一个。使用SEQ MASTER生成ID 湾执行[P_TRG_ACTION]并将ID,Tablename(TableA),Name(Mod1)更新到表B中。
ALTER TRIGGER [dbo].[TRG_ME_ADAPTER_CU] ON [dbo].[ME_ADAPTER_CU]
instead of INSERT, update, delete
AS
BEGIN
DECLARE @P_EVENT VARCHAR(max)
,@P_NEW_ID int
,@P_N_CRTDATE DATETIME2(0)
,@P_N_CRTUSER VARCHAR(max)
,@P_TNAME VARCHAR(max)
,@P_NAME VARCHAR(max)
,@P_N_MODDATE DATETIME2(0)
,@P_N_MODUSER VARCHAR(max)
DECLARE cur_row CURSOR local for select id, NAME from inserted
/* For insert operation-------------*/
IF EXISTS (SELECT * FROM inserted) and NOT EXISTS (SELECT * FROM deleted)
BEGIN
OPEN cur_row
FETCH NEXT FROM cur_row INTO @P_NEW_ID, @P_NAME
WHILE @@Fetch_status = 0
BEGIN
SET @P_NEW_ID = NEXT VALUE FOR dbo.SEQ_MASTER
SELECT @P_EVENT = 'I'
,@P_TNAME = '[dbo].TABLE A'
FROM inserted
SELECT @P_NAME FROM inserted
select @P_N_CRTDATE = GETDATE();
select @P_N_CRTUSER= CURRENT_USER;
EXEC [dbo].[P_TRG_ACTION]
@P_EVENT
,@P_NEW_ID
,@P_N_CRTDATE
,@P_N_CRTUSER
,@P_TNAME
,@P_NAME
FETCH NEXT FROM cur_row INTO @P_NEW_ID, @P_NAME
end
close cur_row
deallocate cur_row
END
P_trg_action
USE [MEV2]
GO
/****** Object: StoredProcedure [dbo].[P_TRG_ACTION] Script Date: 7/2/2015 9:51:06 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[P_TRG_ACTION]
@P_EVENT varchar(max),
@P_NEW_ID int,
@P_N_CRTDATE datetime2(0),
@P_N_CRTUSER varchar(max),
@P_TNAME varchar(max),
@P_NAME varchar(max)
AS
BEGIN
IF @P_EVENT = 'I'
BEGIN
INSERT INTO dbo.TABLE B(TABLENAME, ID, NAME)
VALUES (@P_TNAME, @P_NEW_ID, @P_NAME)
END
END
需要澄清的问题: