Insert into multiple tables using stream & tasks

Viewed 788

As per the official documentation, it depicts as though we can insert into multiple tables from a task. Which sounds inaccurate since

  • Once consumed the offsets of the stream are reset
  • It is possible to execute only one SQL statement from a task

am I missing something here? I want to be able to insert into 2 tables reading out of a stream through the task.

multiple tables

2 Answers

You can do this. Multi-table inserts are one way, but there is another.

The pointer in the stream is only advanced at the end of a transactions. Therefore, you can enclose multiple DML statements that read from the stream in a single transaction. Unfortunately, tasks can only execute a single SQL statements, so you will have to embed your queries in a stored procedure.

Hope this helps.

Related