{"id":104368,"date":"2024-10-31T01:08:50","date_gmt":"2024-10-31T01:08:50","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=104368"},"modified":"2024-10-31T01:08:51","modified_gmt":"2024-10-31T01:08:51","slug":"t-sql-notebooks-manage-views-source-control-and-more","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/t-sql-notebooks-manage-views-source-control-and-more\/","title":{"rendered":"T-SQL Notebooks: Manage Views Source Control and more"},"content":{"rendered":"<p>T-SQL Notebooks is one of the new features announced during FabCon Europe.<\/p>\n<p>The most distracted could miss the fact this is a new feature at all. Yes, it is. Notebooks were capable to support Spark SQL, but T-SQL is something new.<\/p>\n<p>The main examples being announced are built with data warehouses, but let me confirm and highlight this:<\/p>\n<p><strong>T-SQL Notebooks support lakehouses as well.<\/strong><\/p>\n<p>There is at least one limitation: <strong>DML is not supported with lakehouses.<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"306\" class=\"wp-image-104369\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2024\/10\/a-screenshot-of-a-computer-description-automatica-13.png\" alt=\"A screenshot of a computer\n\nDescription automatically generated\" \/><\/p>\n<p>Let&#8217;s start from the beginning.<\/p>\n<h2>The T-SQL Notebooks UI<\/h2>\n<p>The easiest way to create a T-SQL notebook is using the button &#8220;New Query&#8221; at the top of a lakehouse of Data Warehouse. The button has options, and the new one is &#8220;New SQL Query in Notebook&#8221;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"363\" height=\"232\" class=\"wp-image-104370\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2024\/10\/a-screenshot-of-a-computer-description-automatica-14.png\" alt=\"A screenshot of a computer\n\nDescription automatically generated\" \/><\/p>\n<p>Once the notebook is created, it&#8217;s like a regular notebook. You can change the notebook type at the top if you want, but T-SQL is already selected by default.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"456\" height=\"329\" class=\"wp-image-104371\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2024\/10\/a-screenshot-of-a-computer-description-automatica-15.png\" alt=\"A screenshot of a computer\n\nDescription automatically generated\" \/><\/p>\n<p>It has an explorer of warehouses attached, but they can be lakehouses as well. Exactly as in a regular notebook, you can set a default when there are many sources attached. The name of the option is different: &#8220;Primary Warehouse&#8221;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"381\" height=\"355\" class=\"wp-image-104372\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2024\/10\/a-screenshot-of-a-computer-description-automatica-16.png\" alt=\"A screenshot of a computer\n\nDescription automatically generated\" \/><\/p>\n<p>Another interesting feature is the button &#8220;Create Table&#8221;, allowing to transform any SQL query created in the notebook in a new table<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"792\" height=\"720\" class=\"wp-image-104373\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2024\/10\/a-screenshot-of-a-computer-description-automatica-17.png\" alt=\"A screenshot of a computer\n\nDescription automatically generated\" \/><\/p>\n<h2>Scheduled Tasks for Warehouses<\/h2>\n<p>When using the T-SQL notebooks with warehouses, they can be used for the most expected purpose: You can create scheduled processes using the notebooks.<\/p>\n<p>In this way, a team who choose to work with a warehouse doesn&#8217;t need to use pySpark to schedule something, they can use pure T-SQL.<\/p>\n<h2>Version Control for Lakehouse T-SQL Objects<\/h2>\n<p>I suffer with this problem right now, in a solution I work on. How to make version control of lakehouse objects, especially views?<\/p>\n<p>The creation of views is made using the queries created in the SQL Endpoint UI. There is no way to make a version control of these queries.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"414\" height=\"208\" class=\"wp-image-104374\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2024\/10\/a-screenshot-of-a-computer-description-automatica-18.png\" alt=\"A screenshot of a computer\n\nDescription automatically generated\" \/><\/p>\n<p>T-SQL notebooks support the creation of views. We can replace the queries in SQL Endpoints by T-SQL notebooks. We can add them to source control and in this way control the version of the views.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"492\" height=\"142\" class=\"wp-image-104375\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2024\/10\/a-screenshot-of-a-computer-description-automatica-19.png\" alt=\"A screenshot of a computer\n\nDescription automatically generated\" \/><\/p>\n<p>Of course, the notebooks also support deployment pipelines. We can easily use DevOps to create a release pipeline promoting the notebook from one stage to another, executing it in the new stage and making a commit in the workspace.<\/p>\n<h2>Summary<\/h2>\n<p>This is a great advance in source control, and a very unexpected one: <em>While thinking about making an advance on processing creation for a data warehouse, a great advance in source control for lakehouses was also achieved<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>T-SQL Notebooks is one of the new features announced during FabCon Europe. The most distracted could miss the fact this is a new feature at all. Yes, it is. Notebooks were capable to support Spark SQL, but T-SQL is something new. The main examples being announced are built with data warehouses, but let me confirm&#8230;&hellip;<\/p>\n","protected":false},"author":50808,"featured_media":104376,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2,159164],"tags":[158998,158997,159035,101611,4183],"coauthors":[6810],"class_list":["post-104368","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogs","category-microsoft-fabric","tag-lakehouse","tag-microsoft-fabric","tag-notebook","tag-power-bi","tag-t-sql"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/104368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/50808"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=104368"}],"version-history":[{"count":1,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/104368\/revisions"}],"predecessor-version":[{"id":104377,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/104368\/revisions\/104377"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media\/104376"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=104368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=104368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=104368"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=104368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}