sql >> Database >  >> RDS >> Sqlserver

Afvuurtrigger voor bulkinvoeging

u kunt een cursor als volgt gebruiken:

create trigger trg_insertstuff
on [O_SALESMAN]
after insert
as

  DECLARE @SLSMAN_CD NVARCHAR(20)
    DECLARE @SLSMAN_NAME NVARCHAR(20)


 declare db_cursor CURSOR FOR  
SELECT SLSMAN_CD, SLSMAN_NAME
from inserted

OPEN db_cursor  
FETCH NEXT FROM db_cursor INTO @SLSMAN_CD , @SLSMAN_NAME 

WHILE @@FETCH_STATUS = 0  
BEGIN  

IF NOT EXISTS(SELECT * FROM O_SALESMAN_USER WHERE SLSMAN_CD = @SLSMAN_CD)
    BEGIN
        INSERT INTO O_SALESMAN_USER(SLSMAN_CD, PASSWORD, USER_CD)
        VALUES(@SLSMAN_CD, @SLSMAN_CD,@SLSMAN_NAME )
    END


FETCH NEXT FROM db_cursor INTO  @SLSMAN_CD , @SLSMAN_NAME 
end

CLOSE db_cursor  
DEALLOCATE db_cursor


  1. Hoe cyrillisch coderen in mysql?

  2. mysql join 2 tabellen, 2 kolommen

  3. Groepsconcat-resultaten afgesneden

  4. Kan MySQL controleren of dat bestand bestaat?