{"id":7371,"date":"2026-07-28T06:08:29","date_gmt":"2026-07-28T13:08:29","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/azure-sql\/?p=7371"},"modified":"2026-07-27T14:16:47","modified_gmt":"2026-07-27T21:16:47","slug":"refactor-your-database-with-sql-projects-in-vs-code","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azure-sql\/refactor-your-database-with-sql-projects-in-vs-code\/","title":{"rendered":"Refactor your database with SQL projects in VS Code"},"content":{"rendered":"<p class=\"md-end-block md-p md-focus\"><span class=\"md-plain md-expand\">SQL database projects are a fundamental tool for keeping your database in source control, tracking changes and collaborating on quickly evolving database needs. Not to be forgotten, their superpower is being able to dynamically generate deployment scripts that match the declared state and the exact environment you&#8217;re deploying to. SQL project development becomes more challenging when a database needs serious changes, where the requirements of the system have evolved to the point of having to rename tables and move objects between schemas.<\/span><\/p>\n<p><figure id=\"attachment_7380\" aria-labelledby=\"figcaption_attachment_7380\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/Banner.webp\"><img decoding=\"async\" class=\"wp-image-7380\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/Banner-1024x576.webp\" alt=\"Refactoring banner image\" width=\"884\" height=\"497\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/Banner-1024x576.webp 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/Banner-300x169.webp 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/Banner-768x432.webp 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/Banner-1536x864.webp 1536w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/Banner.webp 1920w\" sizes=\"(max-width: 884px) 100vw, 884px\" \/><\/a><figcaption id=\"figcaption_attachment_7380\" class=\"wp-caption-text\">Learn more about SQL projects at aka.ms\/sqlprojects<\/figcaption><\/figure><\/p>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">In plain T-SQL, we can rename a table or column without having to copy or move the data through the <\/span><span class=\"md-pair-s\"><code>sp_rename<\/code><\/span><span class=\"md-plain\"> and modify the schema of an object with <\/span><span class=\"md-pair-s\"><code>ALTER SCHEMA ... TRANSFER<\/code><\/span><span class=\"md-plain\">. In this post we&#8217;ll walk through an example of using SQL projects in VS Code to automatically generate these steps as part of the deployment plan. As a result, we&#8217;ll be able to seamlessly handle significant refactors of our database across multiple environments and continue to capture ongoing development in source control.<\/span><\/p>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">The SQL Database Projects extension for Visual Studio Code supports refactoring database objects while preserving the intent of the change through deployment. When you rename an object or move it between schemas, SQL projects update the source files and record the operation in a refactor log so deployments can use <\/span><span class=\"md-pair-s\"><code>sp_rename<\/code><\/span><span class=\"md-plain\"> or <\/span><span class=\"md-pair-s\"><code>ALTER SCHEMA ... TRANSFER<\/code><\/span><span class=\"md-plain\"> rather than recreating the object. <\/span><\/p>\n<p class=\"md-end-block md-p md-focus\"><strong><span class=\"md-plain md-expand\">Working on the AdventureWorks sample database, the changes we will make are:<\/span><\/strong><\/p>\n<ol>\n<li class=\"md-end-block md-p md-focus\"><span class=\"md-plain md-expand\">add a new schema <\/span><span class=\"md-pair-s\"><code>[ProductCatalog]<\/code><\/span><\/li>\n<li class=\"md-end-block md-p\"><span class=\"md-plain\">move product description to ProductCatalog<\/span><\/li>\n<li class=\"md-end-block md-p\"><span class=\"md-plain md-expand\">rename SalesOrderDetail to SalesOrderLine<\/span><\/li>\n<\/ol>\n<h2>Create a SQL project<\/h2>\n<p>If you don&#8217;t already have an SQL project representing your database, you&#8217;ll want to create one now. You can create an SQL project from a database using either the SqlPackage CLI or one of the IDEs (VS Code, SQL Server Management Studio, Visual Studio). In VS Code, the object explorer database context menu has convenient entries for creating and updating projects from a database.<\/p>\n<p><figure id=\"attachment_7372\" aria-labelledby=\"figcaption_attachment_7372\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/create-project.webp\"><img decoding=\"async\" class=\"wp-image-7372\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/create-project.webp\" alt=\"Create project menu in VS Code mssql object explorer\" width=\"579\" height=\"534\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/create-project.webp 689w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/create-project-300x277.webp 300w\" sizes=\"(max-width: 579px) 100vw, 579px\" \/><\/a><figcaption id=\"figcaption_attachment_7372\" class=\"wp-caption-text\">SQL projects integrated directly with the object explorer in VS Code<\/figcaption><\/figure><\/p>\n<h2 class=\"md-end-block md-heading md-focus\"><span class=\"md-plain md-expand\">Move tables between schemas<\/span><\/h2>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">Creating a new schema in a SQL project is fundamentally adding a new.sql file with the create schema statement in it. Using VS Code, the database projects view includes a menu option for adding an item where several templates are available.<\/span><\/p>\n<p class=\"md-end-block md-p md-focus\"><span class=\"md-plain\">Selecting <\/span><span class=\"md-pair-s \"><strong><span class=\"md-plain\">Add item&#8230;<\/span><\/strong><\/span><span class=\"md-plain md-expand\"> from the SQL project context menu opens this template selection:<\/span><\/p>\n<p><figure id=\"attachment_7373\" aria-labelledby=\"figcaption_attachment_7373\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/item-templates.webp\"><img decoding=\"async\" class=\"wp-image-7373\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/item-templates-1024x544.webp\" alt=\"VS Code SQL projects extension item templates quickpick\" width=\"512\" height=\"272\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/item-templates-1024x544.webp 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/item-templates-300x159.webp 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/item-templates-768x408.webp 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/item-templates.webp 1226w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/a><figcaption id=\"figcaption_attachment_7373\" class=\"wp-caption-text\">SQL project new item templates in VS Code<\/figcaption><\/figure><\/p>\n<p>Using the option for &#8220;Schema&#8221;, we enter the name &#8220;ProductCatalog&#8221; to generate the templated <code>CREATE SCHEMA<\/code> statement immediately in our project.<\/p>\n<p><span class=\"md-plain md-expand\">With a new schema for <\/span><span class=\"md-pair-s\"><code>[ProductCatalog]<\/code><\/span><span class=\"md-plain\">, we&#8217;re ready to move the <\/span><span class=\"md-pair-s\"><code>SalesLT.ProductDescription<\/code><\/span><span class=\"md-plain\"> table to our new schema. Open the <\/span><span class=\"md-pair-s \"><strong><span class=\"md-plain\">ProductDescription.sql<\/span><\/strong><\/span><span class=\"md-plain\"> file in the folder <\/span><span class=\"md-pair-s\"><code>SalesLT\/Tables<\/code><\/span><span class=\"md-plain\"> and right-click on the table name in the text editor to open the context menu. Select <\/span><span class=\"md-pair-s \"><strong><span class=\"md-plain\">Refactor<\/span><\/strong><\/span><span class=\"md-plain\"> from the menu and <\/span><span class=\"md-pair-s \"><strong><span class=\"md-plain\">Move to Schema<\/span><\/strong><\/span><span class=\"md-plain md-expand\"> in the next prompt.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><figure id=\"attachment_7374\" aria-labelledby=\"figcaption_attachment_7374\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/refactor-menu.webp\"><img decoding=\"async\" class=\"wp-image-7374 size-large\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/refactor-menu-1024x576.webp\" alt=\"VS Code mssql editor with context menu open and Refactor option selected\" width=\"1024\" height=\"576\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/refactor-menu-1024x576.webp 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/refactor-menu-300x169.webp 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/refactor-menu-768x432.webp 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/refactor-menu-1536x864.webp 1536w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/refactor-menu.webp 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"figcaption_attachment_7374\" class=\"wp-caption-text\">Database projects view in VS Code with ProductDescription table definition open<\/figcaption><\/figure><\/p>\n<p>All the user schemas in the SQL project will be presented as a list for selection and the updates to the project will be presented for review.<\/p>\n<p><figure id=\"attachment_7375\" aria-labelledby=\"figcaption_attachment_7375\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/new-schema.webp\"><img decoding=\"async\" class=\"wp-image-7375\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/new-schema-1024x248.webp\" alt=\"Schema options when refactoring an object in VS Code SQL projects\" width=\"541\" height=\"131\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/new-schema-1024x248.webp 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/new-schema-300x73.webp 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/new-schema-768x186.webp 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/new-schema.webp 1356w\" sizes=\"(max-width: 541px) 100vw, 541px\" \/><\/a><figcaption id=\"figcaption_attachment_7375\" class=\"wp-caption-text\">Select a destination schema<\/figcaption><\/figure><\/p>\n<p>The review of the changes includes modifying the table definition, any references in additional objects, and the creation\/modification of a refactorlog file.<\/p>\n<p><figure id=\"attachment_7376\" aria-labelledby=\"figcaption_attachment_7376\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/refactor-preview.webp\"><img decoding=\"async\" class=\"wp-image-7376 size-large\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/refactor-preview-1024x683.webp\" alt=\"Preview of a refactor operation in VS Code SQL projects\" width=\"1024\" height=\"683\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/refactor-preview-1024x683.webp 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/refactor-preview-300x200.webp 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/refactor-preview-768x512.webp 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/refactor-preview-1536x1024.webp 1536w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/refactor-preview.webp 2043w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"figcaption_attachment_7376\" class=\"wp-caption-text\">Preview the changes required to wholistically refactor an object in the SQL project<\/figcaption><\/figure><\/p>\n<p class=\"md-end-block md-p md-focus\"><span class=\"md-plain md-expand\">We can choose to <\/span><span class=\"md-pair-s \"><strong><span class=\"md-plain\">Apply<\/span><\/strong><\/span><span class=\"md-plain\"> or discard and cancel the changes. The refactorlog file included in the changes will keep track of changes where the name or schema of an object is changed, ensuring that each deployment is able to track if the movement has been applied. When you commit your project to source control, you should include the <\/span><span class=\"md-pair-s \"><strong><span class=\"md-plain\">ProjectName.refactorlog<\/span><\/strong><\/span><span class=\"md-plain\"> file.<\/span><\/p>\n<h2 class=\"md-end-block md-heading\"><span class=\"md-plain\">Rename a table<\/span><\/h2>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">Another operation that the SQL projects refactoring capability handles well is renaming objects, including tables and columns. Using the refactorlog for table and column renames means that the deployment will be completed without requiring data movement.<\/span><\/p>\n<p class=\"md-end-block md-p md-focus\"><span class=\"md-plain\">To rename the <\/span><span class=\"md-pair-s\"><code>SalesOrderDetail<\/code><\/span><span class=\"md-plain\"> table to <\/span><span class=\"md-pair-s\"><code>SalesOrderLine<\/code><\/span><span class=\"md-plain\">, we access the <\/span><span class=\"md-pair-s \"><strong><span class=\"md-plain\">Rename Symbol<\/span><\/strong><\/span><span class=\"md-plain md-expand\"> menu item. Much like moving an object between schemas, this menu item is in the text editor context menu when we click on the name. Renaming and refactoring options can both be accessed from any object name in the SQL project, including when the object is referenced. For example, a table column can be renamed from the view definition file.<\/span><\/p>\n<p><figure id=\"attachment_7377\" aria-labelledby=\"figcaption_attachment_7377\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/rename-menu.webp\"><img decoding=\"async\" class=\"wp-image-7377 size-large\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/rename-menu-1024x582.webp\" alt=\"VS Code SQL projects text editor with context menu open on an object name\" width=\"1024\" height=\"582\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/rename-menu-1024x582.webp 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/rename-menu-300x170.webp 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/rename-menu-768x436.webp 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/rename-menu-1536x873.webp 1536w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/rename-menu.webp 1700w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"figcaption_attachment_7377\" class=\"wp-caption-text\">Rename an object from the context menu<\/figcaption><\/figure><\/p>\n<p>&nbsp;<\/p>\n<p class=\"md-end-block md-p md-focus\"><span class=\"md-plain md-expand\">When we rename an object, we can immediately apply the changes or preview the rename across the SQL project. Both options will also include updates to the <\/span><span class=\"md-pair-s \"><strong><span class=\"md-plain\">ProjectName.refactorlog<\/span><\/strong><\/span><span class=\"md-plain\"> file. After the move schema and rename operations we&#8217;re applied to the SQL project, our refactorlog contents are:<\/span><\/p>\n<pre class=\"md-fences md-end-block ty-contain-cm modeLoaded\" lang=\"xml\"><span role=\"presentation\"><span class=\"cm-meta\">&lt;?xml<\/span> <span class=\"cm-meta\">version=\"1.0\" encoding=\"utf-8\"?&gt;<\/span><\/span>\r\n<span role=\"presentation\"><span class=\"cm-tag cm-bracket\">&lt;<\/span><span class=\"cm-tag\">Operations<\/span> <span class=\"cm-attribute\">Version<\/span>=<span class=\"cm-string\">\"1.0\"<\/span> <span class=\"cm-attribute\">xmlns<\/span>=<span class=\"cm-string\">\"http:\/\/schemas.microsoft.com\/sqlserver\/dac\/Serialization\/2012\/02\"<\/span><span class=\"cm-tag cm-bracket\">&gt;<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0<span class=\"cm-tag cm-bracket\">&lt;<\/span><span class=\"cm-tag\">Operation<\/span> <span class=\"cm-attribute\">Name<\/span>=<span class=\"cm-string\">\"Move Schema\"<\/span> <span class=\"cm-attribute\">Key<\/span>=<span class=\"cm-string\">\"8f599e45-64ea-4636-a369-139cde876a84\"<\/span> <span class=\"cm-attribute\">ChangeDateTime<\/span>=<span class=\"cm-string\">\"07\/27\/2026 17:06:25\"<\/span><span class=\"cm-tag cm-bracket\">&gt;<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-tag cm-bracket\">&lt;<\/span><span class=\"cm-tag\">Property<\/span> <span class=\"cm-attribute\">Name<\/span>=<span class=\"cm-string\">\"ElementName\"<\/span> <span class=\"cm-attribute\">Value<\/span>=<span class=\"cm-string\">\"[SalesLT].[ProductDescription]\"<\/span> <span class=\"cm-tag cm-bracket\">\/&gt;<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-tag cm-bracket\">&lt;<\/span><span class=\"cm-tag\">Property<\/span> <span class=\"cm-attribute\">Name<\/span>=<span class=\"cm-string\">\"ElementType\"<\/span> <span class=\"cm-attribute\">Value<\/span>=<span class=\"cm-string\">\"SqlTable\"<\/span> <span class=\"cm-tag cm-bracket\">\/&gt;<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-tag cm-bracket\">&lt;<\/span><span class=\"cm-tag\">Property<\/span> <span class=\"cm-attribute\">Name<\/span>=<span class=\"cm-string\">\"NewSchema\"<\/span> <span class=\"cm-attribute\">Value<\/span>=<span class=\"cm-string\">\"ProductCatalog\"<\/span> <span class=\"cm-tag cm-bracket\">\/&gt;<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-tag cm-bracket\">&lt;<\/span><span class=\"cm-tag\">Property<\/span> <span class=\"cm-attribute\">Name<\/span>=<span class=\"cm-string\">\"IsNewSchemaExternal\"<\/span> <span class=\"cm-attribute\">Value<\/span>=<span class=\"cm-string\">\"False\"<\/span> <span class=\"cm-tag cm-bracket\">\/&gt;<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0<span class=\"cm-tag cm-bracket\">&lt;\/<\/span><span class=\"cm-tag\">Operation<\/span><span class=\"cm-tag cm-bracket\">&gt;<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0<span class=\"cm-tag cm-bracket\">&lt;<\/span><span class=\"cm-tag\">Operation<\/span> <span class=\"cm-attribute\">Name<\/span>=<span class=\"cm-string\">\"Rename Refactor\"<\/span> <span class=\"cm-attribute\">Key<\/span>=<span class=\"cm-string\">\"4f955015-b69e-4c8e-b527-761612505adb\"<\/span> <span class=\"cm-attribute\">ChangeDateTime<\/span>=<span class=\"cm-string\">\"07\/27\/2026 17:10:38\"<\/span><span class=\"cm-tag cm-bracket\">&gt;<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-tag cm-bracket\">&lt;<\/span><span class=\"cm-tag\">Property<\/span> <span class=\"cm-attribute\">Name<\/span>=<span class=\"cm-string\">\"ElementName\"<\/span> <span class=\"cm-attribute\">Value<\/span>=<span class=\"cm-string\">\"[SalesLT].[SalesOrderDetail]\"<\/span> <span class=\"cm-tag cm-bracket\">\/&gt;<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-tag cm-bracket\">&lt;<\/span><span class=\"cm-tag\">Property<\/span> <span class=\"cm-attribute\">Name<\/span>=<span class=\"cm-string\">\"ElementType\"<\/span> <span class=\"cm-attribute\">Value<\/span>=<span class=\"cm-string\">\"SqlTable\"<\/span> <span class=\"cm-tag cm-bracket\">\/&gt;<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-tag cm-bracket\">&lt;<\/span><span class=\"cm-tag\">Property<\/span> <span class=\"cm-attribute\">Name<\/span>=<span class=\"cm-string\">\"ParentElementName\"<\/span> <span class=\"cm-attribute\">Value<\/span>=<span class=\"cm-string\">\"[SalesLT]\"<\/span> <span class=\"cm-tag cm-bracket\">\/&gt;<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-tag cm-bracket\">&lt;<\/span><span class=\"cm-tag\">Property<\/span> <span class=\"cm-attribute\">Name<\/span>=<span class=\"cm-string\">\"ParentElementType\"<\/span> <span class=\"cm-attribute\">Value<\/span>=<span class=\"cm-string\">\"SqlSchema\"<\/span> <span class=\"cm-tag cm-bracket\">\/&gt;<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-tag cm-bracket\">&lt;<\/span><span class=\"cm-tag\">Property<\/span> <span class=\"cm-attribute\">Name<\/span>=<span class=\"cm-string\">\"NewName\"<\/span> <span class=\"cm-attribute\">Value<\/span>=<span class=\"cm-string\">\"SalesOrderLine\"<\/span> <span class=\"cm-tag cm-bracket\">\/&gt;<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0<span class=\"cm-tag cm-bracket\">&lt;\/<\/span><span class=\"cm-tag\">Operation<\/span><span class=\"cm-tag cm-bracket\">&gt;<\/span><\/span>\r\n<span role=\"presentation\"><span class=\"cm-tag cm-bracket\">&lt;\/<\/span><span class=\"cm-tag\">Operations<\/span><span class=\"cm-tag cm-bracket\">&gt;<\/span><\/span><\/pre>\n<h2 class=\"md-end-block md-heading\"><span class=\"md-plain\">Deploying our changes<\/span><\/h2>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">The refactorlog itself is integrated into the <\/span><span class=\"md-pair-s\"><code>.dacpac<\/code><\/span><span class=\"md-plain\"> file on project build, and as a result it will be included as part of the deployment whether we&#8217;re working in VS Code, another IDE, or an automated CI\/CD environment.<\/span><\/p>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">From VS Code, we can use the <\/span><span class=\"md-pair-s \"><strong><span class=\"md-plain\">Generate Script<\/span><\/strong><\/span><span class=\"md-plain\"> option to examine the syntax that would be run to apply our changes. The use of refactorlog includes a deployment-managed table <\/span><span class=\"md-pair-s\"><code>dbo.__RefactorLog<\/code><\/span><span class=\"md-plain\">, which will be created by the deployment if it does not already exist. This minimal table tracks the operation keys from the refactorlog when they are applied and enables deployments across multiple iterations of a SQL project to operate seamlessly even when refactoring is involved.<\/span><\/p>\n<pre class=\"md-fences md-end-block ty-contain-cm modeLoaded\" lang=\"sql\"><span role=\"presentation\"><span class=\"cm-keyword\">IF<\/span> OBJECT_ID<span class=\"cm-bracket\">(<\/span><span class=\"cm-keyword\">N<\/span><span class=\"cm-string\">'dbo.__RefactorLog'<\/span><span class=\"cm-bracket\">)<\/span> <span class=\"cm-keyword\">IS<\/span> <span class=\"cm-atom\">NULL<\/span><\/span>\r\n<span role=\"presentation\"><span class=\"cm-keyword\">BEGIN<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0 \u00a0<span class=\"cm-keyword\">CREATE<\/span> <span class=\"cm-keyword\">TABLE<\/span> <span class=\"cm-bracket\">[<\/span>dbo<span class=\"cm-bracket\">]<\/span>.<span class=\"cm-bracket\">[<\/span>__RefactorLog<span class=\"cm-bracket\">]<\/span> <span class=\"cm-bracket\">(<\/span>OperationKey UNIQUEIDENTIFIER <span class=\"cm-keyword\">NOT<\/span> <span class=\"cm-atom\">NULL<\/span> <span class=\"cm-keyword\">PRIMARY<\/span> <span class=\"cm-keyword\">KEY<\/span><span class=\"cm-bracket\">)<\/span><\/span>\r\n<span role=\"presentation\"> \u00a0  EXEC sp_addextendedproperty <span class=\"cm-keyword\">N<\/span><span class=\"cm-string\">'microsoft_database_tools_support'<\/span><span class=\"cm-punctuation\">,<\/span> <span class=\"cm-keyword\">N<\/span><span class=\"cm-string\">'refactoring log'<\/span><span class=\"cm-punctuation\">,<\/span> <span class=\"cm-keyword\">N<\/span><span class=\"cm-string\">'schema'<\/span><span class=\"cm-punctuation\">,<\/span> <span class=\"cm-keyword\">N<\/span><span class=\"cm-string\">'dbo'<\/span><span class=\"cm-punctuation\">,<\/span> <span class=\"cm-keyword\">N<\/span><span class=\"cm-string\">'table'<\/span><span class=\"cm-punctuation\">,<\/span> <span class=\"cm-keyword\">N<\/span><span class=\"cm-string\">'__RefactorLog'<\/span><\/span>\r\n<span role=\"presentation\"><span class=\"cm-keyword\">END<\/span><\/span><\/pre>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">If you look through the generated deployment script, you&#8217;ll also notice the use of <\/span><span class=\"md-pair-s\"><code>sp_rename<\/code><\/span><span class=\"md-plain\"> and <\/span><span class=\"md-pair-s\"><code>ALTER SCHEMA ... TRANSFER<\/code><\/span><span class=\"md-plain\"> for the refactor operations that need to be applied in that environment. A section of the deployment script is show below, including the print statements that reference specific refactorlog keys.<\/span><\/p>\n<pre class=\"prettyprint language-sql\"><code class=\"language-sql\">...\r\nCREATE SCHEMA [ProductCatalog];\r\n\u200b\r\n\u200b\r\nGO\r\nPRINT N'The following operation was generated from a refactoring log file 8f599e45-64ea-4636-a369-139cde876a84';\r\n\u200b\r\nPRINT N'Move object [SalesLT].[ProductDescription] to different schema [ProductCatalog]';\r\n\u200b\r\n\u200b\r\nGO\r\nALTER SCHEMA [ProductCatalog] TRANSFER [SalesLT].[ProductDescription];\r\n\u200b\r\n\u200b\r\nGO\r\nPRINT N'The following operation was generated from a refactoring log file 4f955015-b69e-4c8e-b527-761612505adb';\r\n\u200b\r\nPRINT N'Rename [SalesLT].[SalesOrderDetail] to SalesOrderLine';\r\n\u200b\r\n\u200b\r\nGO\r\nEXECUTE sp_rename @objname = N'[SalesLT].[SalesOrderDetail]', @newname = N'SalesOrderLine', @objtype = N'OBJECT';\r\n...<\/code><\/pre>\n<p class=\"md-end-block md-p md-focus\"><span class=\"md-plain\">These same statements are used if the deployment is run as a direct <\/span><span class=\"md-pair-s \"><strong><span class=\"md-plain\">Publish<\/span><\/strong><\/span><span class=\"md-plain\"> operation. Because the refactorlog is packaged into the <\/span><span class=\"md-pair-s\"><code>.dacpac<\/code><\/span><span class=\"md-plain md-expand\"> file, you&#8217;re able to use refactorlogs in CI\/CD pipelines without any changes to existing artifact publishing and archival.<\/span><\/p>\n<p>Once the deployment is completed, our original database is updated to match the renamed table &#8220;SalesOrderLine&#8221; and the table &#8220;ProductDescription&#8221; has been moved to the &#8220;ProductCatalog&#8221; schema.<\/p>\n<p><figure id=\"attachment_7378\" aria-labelledby=\"figcaption_attachment_7378\" class=\"wp-caption aligncenter\" ><a href=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/resulting-deployment-scaled.webp\"><img decoding=\"async\" class=\"wp-image-7378 size-large\" src=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/resulting-deployment-1024x575.webp\" alt=\"Database after deployment of refactoring operations\" width=\"1024\" height=\"575\" srcset=\"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/resulting-deployment-1024x575.webp 1024w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/resulting-deployment-300x169.webp 300w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/resulting-deployment-768x432.webp 768w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/resulting-deployment-1536x863.webp 1536w, https:\/\/devblogs.microsoft.com\/azure-sql\/wp-content\/uploads\/sites\/56\/2026\/07\/resulting-deployment-2048x1151.webp 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"figcaption_attachment_7378\" class=\"wp-caption-text\">Updated database with our refactoring changes<\/figcaption><\/figure><\/p>\n<h2 class=\"md-end-block md-heading md-focus\"><span class=\"md-plain md-expand\">Learn more<\/span><\/h2>\n<p class=\"md-end-block md-p\"><span class=\"md-plain\">Get to know the SQL Database Projects extension in VS Code through the overall SQL projects documentation (<\/span><span class=\"md-link md-pair-s\"><a href=\"https:\/\/aka.ms\/sqlprojects\">https:\/\/aka.ms\/sqlprojects<\/a><\/span><span class=\"md-plain\">) and the SQL Database Projects extension <\/span><span class=\"md-meta-i-c md-link\"><a href=\"https:\/\/learn.microsoft.com\/sql\/tools\/visual-studio-code-extensions\/sql-database-projects\/getting-started-sql-database-projects-extension\"><span class=\"md-plain\">getting started guide<\/span><\/a><\/span><span class=\"md-plain\">.<\/span><\/p>\n<p class=\"md-end-block md-p md-focus\"><span class=\"md-plain\">Learn more about refactoring in SQL projects from the SQL projects <\/span><span class=\"md-meta-i-c md-link\"><a href=\"https:\/\/learn.microsoft.com\/sql\/tools\/sql-database-projects\/concepts\/refactor-overview\"><span class=\"md-plain\">concepts documentation<\/span><\/a> on refactoring<\/span><span class=\"md-plain md-expand\">.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p class=\"md-end-block md-p md-focus\">\n","protected":false},"excerpt":{"rendered":"<p>SQL database projects are a fundamental tool for keeping your database in source control, tracking changes and collaborating on quickly evolving database needs. Not to be forgotten, their superpower is being able to dynamically generate deployment scripts that match the declared state and the exact environment you&#8217;re deploying to. SQL project development becomes more challenging [&hellip;]<\/p>\n","protected":false},"author":46830,"featured_media":7380,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[92,625],"tags":[],"class_list":["post-7371","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-vs-code"],"acf":[],"blog_post_summary":"<p>SQL database projects are a fundamental tool for keeping your database in source control, tracking changes and collaborating on quickly evolving database needs. Not to be forgotten, their superpower is being able to dynamically generate deployment scripts that match the declared state and the exact environment you&#8217;re deploying to. SQL project development becomes more challenging [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/7371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/users\/46830"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/comments?post=7371"}],"version-history":[{"count":1,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/7371\/revisions"}],"predecessor-version":[{"id":7390,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/posts\/7371\/revisions\/7390"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media\/7380"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/media?parent=7371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/categories?post=7371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azure-sql\/wp-json\/wp\/v2\/tags?post=7371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}