Forum Discussion
How to perform DML(insert/delete/update) on Fabric SQL database using Notebook
- 1 year ago
Hi mail2atulm,
To perform INSERT, UPDATE, and Delete operations on your Fabric SQL database directly from a Fabric notebook within the same workspace. If your database is a Fabric Warehouse or a Mirrored SQL database with an analytics endpoint, the easiest way is to use the %%sql magic command in the notebook. You can simply write standard T-SQL commands like INSERT, UPDATE or Delete
inside a %%sql cell, and it will execute directly against your database.If you're using a Spark-based notebook or need more control, you can also connect to your Fabric SQL database using a JDBC connection within Python. This lets you write data from a DataFrame to your SQL table or execute more complex logic programmatically. You'll need your database connection details like the endpoint, database name, and credentials (or managed identity), and then you can use Spark’s write jdbc() function to perform your DML tasks. For more detailed guidance, you can refer to the official documentation on connecting to your SQL database in Microsoft Fabric: Connect to Your SQL Database - Microsoft Fabric.(Microsoft Learn)
Thanks,
Prashanth Are
MS Fabric community support
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly and give Kudos if helped you resolve your query
Hi mail2atulm,
To perform INSERT, UPDATE, and Delete operations on your Fabric SQL database directly from a Fabric notebook within the same workspace. If your database is a Fabric Warehouse or a Mirrored SQL database with an analytics endpoint, the easiest way is to use the %%sql magic command in the notebook. You can simply write standard T-SQL commands like INSERT, UPDATE or Delete inside a %%sql cell, and it will execute directly against your database.
If you're using a Spark-based notebook or need more control, you can also connect to your Fabric SQL database using a JDBC connection within Python. This lets you write data from a DataFrame to your SQL table or execute more complex logic programmatically. You'll need your database connection details like the endpoint, database name, and credentials (or managed identity), and then you can use Spark’s write jdbc() function to perform your DML tasks. For more detailed guidance, you can refer to the official documentation on connecting to your SQL database in Microsoft Fabric: Connect to Your SQL Database - Microsoft Fabric.(Microsoft Learn)
Thanks,
Prashanth Are
MS Fabric community support
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly and give Kudos if helped you resolve your query