Forum Discussion
Can notebooks trigger SQL stored procedures in 2026?
Greetings, community. I know Microsoft has released some newer features around notebooks and SQL interactions, so I was wondering: is it possible to trigger a sproc in a Fabric DW from a Fabric notebook using PySpark?
We have a situation where we need the notebook to "stage" data, trigger a sproc that performs a number of steps that aren't easily done via notebooks, and then proceed with notebook operations.
Hi arpost
The way I would approach this is to use a data pipeline or a pipeline where you could have the first 5 cells in your notebook running something. Once that completes, you then execute the stored procedures followed by the next step where you have another notebook which concretes the additional cells in your notebook. This way it'll also allow you to know if something fails in the pipeline, where it is failed, or easier troubleshooting and potentially. Problem solving.
I agree with GilbertQ about calling notebooks and stored procs from a pipeline as you have better control.
If you must call the stored proc from the notebook, they have released a feature that's in preview.
Make sure its a "python" notebook (not pyspark (python)).
You will have to pass the magic command as follows:
%%tsql -artifact NameOfYourFabricWarehouse -type Warehouse -bind df1You can find more details here: https://learn.microsoft.com/en-us/fabric/data-engineering/tsql-magic-command-notebook#using-t-sql-magic-command-to-query-fabric-data-warehouse
If you like my answer, please gives a thumbs up. If I have answered you correctly, please mark this as a solution.
Best Regards,
Rajesh
5 Replies
- GilbertQSuper User
Hi arpost
The way I would approach this is to use a data pipeline or a pipeline where you could have the first 5 cells in your notebook running something. Once that completes, you then execute the stored procedures followed by the next step where you have another notebook which concretes the additional cells in your notebook. This way it'll also allow you to know if something fails in the pipeline, where it is failed, or easier troubleshooting and potentially. Problem solving.
- BrandonHartAdvocate I
By the way, learning the hard way from experience. I recommend to almost always wrap your notebooks in a Pipeline. It gives you extra control such as set execution timeouts.
- RajeshMAdvocate II
I agree with GilbertQ about calling notebooks and stored procs from a pipeline as you have better control.
If you must call the stored proc from the notebook, they have released a feature that's in preview.
Make sure its a "python" notebook (not pyspark (python)).
You will have to pass the magic command as follows:
%%tsql -artifact NameOfYourFabricWarehouse -type Warehouse -bind df1You can find more details here: https://learn.microsoft.com/en-us/fabric/data-engineering/tsql-magic-command-notebook#using-t-sql-magic-command-to-query-fabric-data-warehouse
If you like my answer, please gives a thumbs up. If I have answered you correctly, please mark this as a solution.
Best Regards,
Rajesh
- v-achippaCommunity Support
Hi arpost,
Thank you for reaching out to Microsoft Fabric Community.
Thank you GilbertQ and RajeshM for the prompt response.
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the user's for the issue worked? or let us know if you need any further assistance.
Thanks and regards,
Anjan Kumar Chippa