Asked by:
Formas de trigger after insert

Question
-
Boa tarde,
Preciso identificar um insert em uma tabela e executar alguns códigos de banco, no entanto não posso criar uma trigger nesse banco de dados, eu teria alguma alternativa para isso?
Wednesday, May 17, 2017 6:23 PM
All replies
-
Boa tarde! O que você está tentando fazer?Wednesday, May 17, 2017 6:28 PM
-
Preciso executar um insert em outro banco de dadosWednesday, May 17, 2017 6:37 PM
-
Adicione o tipo de dados rowversion para sua mesa. Em seguida, crie um trabalho de servidor de sql que é executado a cada 10 minutos, por exemplo. Ele registra o último valor rowversion usado e em seguida faz um select na tabela no banco de dados diferente.Wednesday, May 17, 2017 6:45 PM
-
Hi pedro
In your scenario, you want to create a trigger to insert table in another database. Right?
Are they in the same server? If so you can try:CREATE TRIGGER my_tr ON tbl FOR INSERT AT INSERT INTO dbname.dbo.tbl (col1, col2 ...) SELECT col1, col2, ...... FROM inserted
If you are using remote server. I would suggest you to create a linked server . Then try the script like:
CREATE TRIGGER my_tr ON tbl FOR INSERT AT INSERT INTO server1.dbname.dbo.tbl (col1, col2 ...) SELECT col1, col2, ...... FROM inserted
Reference: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/d135b083-48b6-4c23-bf72-f6ddf728068f/writing-a-trigger-which-inserts-row-in-another-database? Forum = sqlgetstarted
If you still have any question, please feel free to ask.
Thanks,
Xi Jin.MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Thursday, May 18, 2017 2:44 AM