azure cli,azure上傳代碼_深入了解Azure Data Studio:更多代碼和更少GUI

 2023-10-18 阅读 23 评论 0

摘要:azure上傳代碼 In the previous two articles, Starting your journey with Azure Data Studio and Developing your SQL Server database using Azure Data Studio, we introduced the Azure Data Studio tool by describing the main components of that data studio and sh

azure上傳代碼

In the previous two articles, Starting your journey with Azure Data Studio and Developing your SQL Server database using Azure Data Studio, we introduced the Azure Data Studio tool by describing the main components of that data studio and showed how we can take advantages from it in developing and organizing the database related projects.

在前兩篇文章《 開始使用Azure Data Studio和使用Azure Data Studio 開發SQL Server數據庫》中 ,我們通過描述該Data Studio的主要組件并介紹了如何利用它來介紹Azure Data Studio工具。開發和組織與數據庫相關的項目。

In this article, we will go deeper and present the advanced tasks that can be performed using the Azure Data Studio.

在本文中,我們將更深入地介紹可以使用Azure Data Studio執行的高級任務。

在你開始前 (Before you start)

azure cli、 Azure Data Studio is a dynamic tool that is reviewed continuously based on the users’ feedback. Also, it introduced many features that are still under preview and updated frequently. In order to keep the version that is installed on your machine up-to-date and with the latest features and the bug fixes, it is recommended to update it continuously.

Azure Data Studio是一個動態工具,可以根據用戶的反饋對其進行連續審查。 此外,它引入了許多功能,這些功能仍在預覽中并經常更新。 為了使計算機上安裝的版本保持最新,并具有最新功能和錯誤修復,建議不斷對其進行更新。

To update the Azure Data Studio, open the tool and choose the Restart to Update option from the Help menu, and the studio will be closed, updated with the latest changes then opened automatically, as shown below:

若要更新Azure Data Studio,請打開該工具,然后從“ 幫助”菜單中選擇“ 重新啟動以更新”選項,然后該工作室將關閉,使用最新更改進行更新,然后自動打開,如下所示:

Restart to Update

After updating Azure Data Studio, it is recommended to organize SQL Server instances in your environment within groups. This will make it easier for you to directly identify the server that you manage to use in your project. For example, you can create a group for all SQL Server instances in the development environment, another servers group for the testing environment, and a restricted group for the production environment.

azure 虛擬機? 更新Azure Data Studio之后,建議將您的環境中SQL Server實例組織在組中。 這將使您更容易直接識別要在項目中使用的服務器。 例如,您可以為開發環境中的所有SQL Server實例創建一個組,為測試環境創建另一個服務器組,為生產環境創建一個受限組。

To achieve that, click on the New Server Group button, under the Connections tab, as below:

為此,請單擊“ 連接”選項卡下的“ 新建服務器組”按鈕,如下所示:

New Server Group

From the Add server group window, provide the name and the description for that server group in addition to color to distinguish that group quickly. In the example below, we will create three servers’ groups: Dev, UAT, and Prod:

在“ 添加服務器組”窗口中,除了提供顏色外,還要提供該服務器組的名稱和描述,以快速區分該組。 在下面的示例中,我們將創建三個服務器組:Dev,UAT和Prod:

azure data studio設置中文、

Add Server Group

Now the server groups are created successfully. To add servers to these groups, choose the related server group name from the group’s drop-down list, during the connection creation process, or modify the recent or the saved connections with the correct group name, and the servers will be displayed directly under the corresponding group when connecting to that server:

現在,服務器組已成功創建。 要將服務器添加到這些組中,請在連接創建過程中從組的下拉列表中選擇相關的服務器組名稱,或使用正確的組名稱修改最近的或保存的連接,服務器將直接顯示在連接到該服務器時對應的組:

Add Servers to Groups

開發存儲過程 (Developing stored procedures)

Azure Data Studio contains a rich query editor that allows us to develop any database object easily with a few clicks. In the previous article, we showed how to create a new database, a new table, and modify the table’s data without the need to be a skilled database developer.

Azure Data Studio包含一個豐富的查詢編輯器,使我們能夠通過單擊幾下輕松地開發任何數據庫對象。 在上一篇文章中,我們展示了如何創建新數據庫,新表以及如何修改表的數據,而無需成為熟練的數據庫開發人員。

vscode上傳代碼到github、 In this example, we will show how to develop a new stored procedure.

在此示例中,我們將顯示如何開發新的存儲過程。

The first step here is to connect to the SQL Server instance that hosts the database where the stored procedure will be created. This can be achieved by different methods like choosing to Create a Connection from the Welcome page, and provide the name of the SQL Server instance, the authentication method and the credentials that will be used to connect to that SQL Server, as below:

第一步是連接到承載將在其中創建存儲過程的數據庫SQL Server實例。 這可以通過不同的方法來實現,例如從“歡迎”頁面選擇“ 創建連接 ”,并提供SQL Server實例的名稱,身份驗證方法和將用于連接到該SQL Server的憑據,如下所示:

Create a Connection

After connecting to the SQL Server instance, open the query editor window by choosing New Query option from the File menu, or simply right-clicking on the database that you are interested in creating the stored procedure and choose New Query option, as indicated below:

azure開發, 連接到SQL Server實例后,從文件菜單中選擇新建查詢選項打開查詢編輯器窗口,或者只需右鍵點擊你有興趣創建存儲過程,并選擇新建查詢選項,如下文所示的數據庫:

New Query

If the query editor window is still showed as disconnected, click on the Connect option and select the name of the connection that represents the SQL Server instance that hosts your database.

如果查詢編輯器窗口仍然顯示為已斷開連接,請單擊“ 連接”選項,然后選擇代表承載數據庫SQL Server實例的連接的名稱。

To create a new stored procedure, you can take advantage of the built-in IntelliSense feature that automatically completes the statement you are trying to write or the snippets code feature that provides you with templates for the object you manage to create.

要創建新的存儲過程,您可以利用內置的IntelliSense功能(該功能自動完成您要編寫的語句)或摘要代碼功能(該功能為您提供要創建的對象的模板)。

In our demo here, we will use the “Create a Stored procedure” snippet to provide us with the template that can make it easier for us to create that stored procedure and fill only the basic information without recalling the full syntax for the CREATE PROC T-SQL statement.

在此處的演示中,我們將使用“創建存儲過程”代碼段為我們提供模板,該模板可使我們更輕松地創建該存儲過程并僅填寫基本信息,而無需調用CREATE PROC T的完整語法。 -SQL語句。

In the below snippet, you will see that the script will be in the form of “drop, create then execute”. Where it will check first if there is any stored procedure with the same name and drop it before creating the new one then provide the statement that is used to execute that stored procedure for verification purposes, as shown below:

在下面的代碼片段中,您將看到腳本的形式為“刪除,創建然后執行”。 它將首先檢查是否存在任何同名存儲過程,并在創建新存儲過程之前將其刪除,然后提供用于執行該存儲過程的語句以進行驗證,如下所示:

CREATE PROC Sinppet

In addition to the useful template, the Azure Data Studio query editor is clever in a way that helps to change all occurrences for a specific statement in the whole document. This will help if you plan to change the default name of the stored procedure wherever it is used.

除了有用的模板之外,Azure Data Studio查詢編輯器還很聰明,可以幫助更改整個文檔中特定語句的所有匹配項。 如果您計劃更改使用存儲過程的默認名稱,這將有所幫助。

This can be achieved by selecting the text that you plan to change, right-click on that text, and choose Change All Occurrences option. When you write the new name for the stored procedure, you will see that the cursor is pointing to all text occurrences and the value is changing simultaneously in all cursor locations:

這可以通過選擇計劃更改的文本,右鍵單擊該文本并選擇“ 更改所有出現次數”選項來實現。 當為存儲過程編寫新名稱時,您將看到光標指向所有出現的文本,并且值在所有光標位置同時改變:

Change All Occurrences

If you are still not surprised by the functionalities of this query editor, Azure Data Studio will make you astonished with the Peek Definition feature.

如果您對該查詢編輯器的功能仍然不感到驚訝,則Azure Data Studio將使您對Peek Definition功能感到驚訝。

When we create a stored procedure that is reading from a table that contains a large number of columns or reading from multiple tables and joins between these tables, it is not easy to recall the name of all the columns, the constraints on these columns, and the relations between the tables. Not to mention that visiting the schema of the table is not user-friendly.

當我們創建一個從包含大量列的表中讀取或從多個表中讀取并在這些表之間進行聯接的存儲過程時,要想起所有列的名稱,這些列的約束以及表之間的關系。 更不用說訪問表的架構不是用戶友好的。

I agree with you that the IntelliSense feature is helpful to get the name of the tables and the columns, but this requires from you to remember part of the names to get the complete name automatically, as can be seen below:

我同意您的看法,IntelliSense功能有助于獲取表和列的名稱,但這需要您記住部分名稱才能自動獲取完整名稱,如下所示:

IntelliSense

To overcome this issue, Azure Data Studio introduces a feature that helps you open the script that is used to create a specific database object as a pop-up in the same window where you are developing your stored procedure. This is similar to the script that is generating when trying to “Script as Create” for a specific table.

為解決此問題,Azure Data Studio引入了一項功能,可幫助您在開發存儲過程的同一窗口中打開用于創建特定數據庫對象的腳本作為彈出窗口。 這類似于嘗試為特定表“創建時編寫腳本”時生成的腳本。

Assume that we plan to use the Employee table in the stored procedure that we are developing. Also, this table contains a large number of columns that do not follow a specific naming convention. So, it is not easy to recall these names.

假設我們計劃在我們正在開發的存儲過程中使用Employee表。 此外,此表包含大量不遵循特定命名約定的列。 因此,要記住這些名稱并不容易。

To display the schema of that table, including the name of the columns, the data types, the constraints and relations, right-click on the name of that table in your stored procedure and choose to Peek Definition option from the Peek options list, and a dark blue pop-up window will be displayed, that contains the schema definition for that table, where you can easily read it and use the displayed information to write your query in the stored procedure at the same time:

要顯示該表的架構,包括列名,數據類型,約束和關系,請在存儲過程中右鍵單擊該表的名稱,然后從“ Peek”選項列表中選擇“ Peek Definition”選項,然后將顯示一個深藍色的彈出窗口,其中包含該表的架構定義,您可以在其中輕松讀取表并使用顯示的信息同時在存儲過程中編寫查詢:

Peek Definition

The Go to Definition option in the previous window is helpful when you want to check the definition of another database object, such as stored procedure or function, that is used in that script, without the need to browse it under the database objects list.

如果要檢查該腳本中使用的另一個數據庫對象(例如存儲過程或函數)的定義,而無需在數據庫對象列表下瀏覽它,則可以使用前一個窗口中的“ 轉到定義”選項。

Once you finish writing your stored procedure script, click on the Run option to execute the CREATE PROC statement that will create the stored procedure under the selected database, as you can see below:

一旦完成存儲過程腳本的編寫,請單擊“ 運行”選項以執行CREATE PROC語句,該語句將在所選數據庫下創建存儲過程,如下所示:

create the stored procedure

To modify any stored procedure, view or function under a specific database, right-click on that database object, and choose Script as Alter option, where a new window with ALTER PROC script for that object will be displayed, allowing you to modify it as per your requirements.

要修改特定數據庫下的任何存儲過程,視圖或函數,請在該數據庫對象上單擊鼠標右鍵,然后選擇“ 腳本作為更改”選項,其中將顯示一個帶有該對象的帶有ALTER PROC腳本的新窗口,您可以將其修改為根據您的要求。

Other useful options displayed in the same list is generating script to create that stored procedure in order to create it in another database or server, script as drop option to generate a T-SQL statement used to drop that procedure and script as execute option to generate the T-SQL statement that can be used to execute that procedure:

在同一列表中顯示的其他有用的選項是生成腳本以創建該存儲過程以便在另一個數據庫或服務器中創建它,腳本作為drop選項來生成用于刪除該過程的T-SQL語句,腳本作為execute選項來生成可用于執行該過程的T-SQL語句:

Script as Alter

安全發展 (Security development)

We mentioned in the previous articles that the Azure Data Studio is not a database administration tool, and it provides no GUI for most of the administration tasks.

我們在之前的文章中提到過,Azure Data Studio不是數據庫管理工具,并且它不為大多數管理任務提供GUI。

For instance, to create a new server login, a database user, or grant or revoke permission on a specific database object for that user, you need to write a T-SQL script to achieve that.

例如,要創建一個新的服務器登錄名,一個數據庫用戶,或為該用戶授予或撤銷對特定數據庫對象的權限,您需要編寫一個T-SQL腳本來實現。

Again, with the help of the IntelliSense and Snippet code features, this task is not hard. For example, the script below can be used to create a new SQL Server Authentication login, map the user to a specific database and grant him owner permission on that database, as demonstrated below:

同樣,借助IntelliSense和Snippet代碼功能,此任務并不難。 例如,下面的腳本可用于創建新SQL Server身份驗證登錄名,將用戶映射到特定數據庫并向該用戶授予對該數據庫的所有者權限,如下所示:

Security development

SQLCMD (SQLCMD)

The query editor of Azure Data Studio provides us with the ability to use the interactive sqlcmd command-line utility to write Windows system commands and T-SQL statements in the same script.

Azure Data Studio的查詢編輯器使我們能夠使用交互式sqlcmd命令行實用程序在同一腳本中編寫Windows系統命令和T-SQL語句。

To achieve that, click on the Enable SQLCMD option at the top left side of the query editor and write your “hybrid” code that contains Windows and T-SQL statements, and it will be parsed and executed successfully:

為此,請單擊查詢編輯器左上角的“ 啟用S??QLCMD”選項,然后編寫包含Windows和T-SQL語句的“混合”代碼,它將成功解析并執行:

SQLCMD

電源外殼 (PowerShell)

Yes! Rather than opening a separate console to execute PowerShell commands, Azure Data Studio can be used to run these commands directly via the studio terminal.

是! 無需打開單獨的控制臺來執行PowerShell命令,而是可以使用Azure Data Studio通過Studio終端直接運行這些命令。

The terminal window can be opened by choosing the Terminal option under the View menu, then used to write and execute your PowerShell commands directly, as you can observe below:

可以通過選擇“ 視圖”菜單下的“ 終端”選項來打開終端窗口,然后直接用于編寫和執行PowerShell命令,如下所示:

PowerShell

備份還原 (Backup and restore)

The responsibility of performing, tracking, and monitoring the backup and restore process is on the database administrators. But the database developers, who are performing changes to the database schema and data, at least in the development environment, need to perform backup and restore the database frequently.

執行,跟蹤和監視備份和還原過程的責任在于數據庫管理員。 但是,至少在開發環境中要對數據庫架構和數據進行更改的數據庫開發人員需要經常執行備份和還原數據庫。

Fortunately, Azure Data Studio provides us with the ability to manually perform the backup and restore operations directly from the same studio, using a backup and restore wizards very similar to the ones we are familiar with in the SSMS tool.

幸運的是,Azure Data Studio使我們能夠使用非常類似于我們在SSMS工具中熟悉的備份和還原向導,直接從同一工作室手動執行備份和還原操作。

To take a new backup for a specific database, right-click on that database, and choose the Backup option. From the Backup database wizard, specify the name, type, and properties of the backup process then click on Backup option to take a backup or generate a script to perform the backup later, as is shown:

要為特定數據庫進行新備份,請右鍵單擊該數據庫,然后選擇“ 備份”選項。 在“ 備份數據庫”向導中,指定備份過程的名稱,類型和屬性,然后單擊“ 備份”選項以進行備份或生成腳本以稍后執行備份,如下所示:

Backup

Once the backup operation is completed, based on the displayed Tasks window with the backup operation process, you can restore that backup file to another SQL Server instance, or the same instance with another name, by right-clicking on the SQL Server instance name and choose to Restore option, then choose the location of the backup file and the restore options, similar to the SSMS ones, and click on the Restore option to start the restoration process, or generate script to restore the database later.

備份操作完成后,根據顯示的帶有備份操作過程的“ 任務”窗口,您可以通過右鍵單擊SQL Server實例名稱,將備份文件還原到另一個SQL Server實例或具有另一個名稱的同一實例。選擇“還原”選項,然后選擇備份文件的位置以及與SSMS類似的還原選項,然后單擊“ 還原”選項以啟動還原過程,或生成腳本以稍后還原數據庫。

You can monitor the progress of the restore operation too from the automatically displayed Tasks window, as you can see below:

您也可以從自動顯示的“ 任務”窗口中監視還原操作的進度,如下所示:

Restore

The history of all backup operations performed on a specific SQL Server instance, which contains useful information for the database developers to monitor the versioning of the databases during their development process, can be tracked from the Home page of that SQL Server instance, that can be displayed by right-clicking on the SQL Server instance and choose the Manage option.

可以從該SQL Server實例的主頁上跟蹤在特定SQL Server實例上執行的所有備份操作的歷史記錄,其中包含有用的信息,供數據庫開發人員在數據庫開發過程中監視數據庫的版本控制。通過在SQL Server實例上單擊鼠標右鍵并選擇“ 管理”選項來顯示。

The backup status summary window displays statistical information about the backup processes that are performed for the databases hosted in that instance. To get detailed information, click on the three dots beside in that summary box and review the displayed insight:

備份狀態摘要窗口顯示有關對該實例中托管的數據庫執行的備份過程的統計信息。 要獲取詳細信息,請單擊該摘要框中旁邊的三個點并查看顯示的見解:

Backup Info

結論 (Conclusion)

In this article, we went through many useful functionalities that are provided by the Azure Data Studio to make our database development tasks easier and more organized.

在本文中,我們介紹了Azure Data Studio提供的許多有用的功能,以使我們的數據庫開發任務更輕松,更有條理。

In the next article, we will see how to extend the built-in functionalities of the Azure Data Studio and how to manage an Azure SQL Database within that data studio. Stay tuned!

在下一篇文章中,我們將看到如何擴展Azure Data Studio的內置功能以及如何在該Data Studio中管理Azure SQL數據庫。 敬請關注!

翻譯自: https://www.sqlshack.com/digging-deeper-into-azure-data-studio-more-code-and-less-gui/

azure上傳代碼

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/144531.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息