Home > database >  MSSQL trigger problems
MSSQL trigger problems

Time:09-22

I watch A data insert, B table can be synchronous, but the new insert A data, is N duplicate data, the code is written so,

Create the Trigger TAgent

On [the apply]

For the Insert

As

The begin

INSERT INTO [test] [dbo]. [apply1]

SELECT [applycode]

, [amount]

, [managercode]

The FROM [test] [dbo]. [the apply]





Then I put the SELECT top 1 [applycode] to SELECT [applycode], but I only repeat a data, how to do? O solve,,,

Create the Trigger TAgent

On [the apply]

SELECT the top 1 [applycode]

As

The begin

INSERT INTO [test] [dbo]. [apply1]

SELECT [applycode]

, [amount]

, [managercode]

The FROM [test] [dbo]. [the apply]


Any good triggers, or how to synchronize data to a table b table, insert only once, perhaps,

CodePudding user response:

Try to use "SELECT DISTINCT" to see if it will work.

CodePudding user response:

The Select without conditions, so the duplicate,

CodePudding user response:

 CREATE TRIGGER TAgent 
ON [the apply]
AFTER INSERT
AS
The BEGIN
INSERT INTO [test] [dbo]. [apply1]
SELECT [applycode],
[amount],
[managercode]
The FROM INSERTED - should be this to
END
GO


Suggest you read the trigger knowledge complete again and again to write code,
  • Related