博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
批量关停azure vm_如何在Azure中使用Visual Studio和VM数据库
阅读量:2511 次
发布时间:2019-05-11

本文共 8445 字,大约阅读时间需要 28 分钟。

批量关停azure vm

介绍 ( Introduction )

In this new article, we will use Visual Studio to connect to a SQL Server Database Installed in a Virtual Machine in Azure.

在这篇新文章中,我们将使用Visual Studio连接到安装在Azure虚拟机中SQL Server数据库。

Visual Studio is one of the most popular development tools in the world and connecting to Azure with Visual Studio is a very common need.

Visual Studio是世界上最受欢迎的开发工具之一,通过Visual Studio连接到Azure是非常普遍的需求。

We will modify an existing SQL Server table in Azure from Visual Studio. Later we will create a stored procedure and finally, we will create an inline table-valued function.

我们将从Visual Studio修改Azure中现有SQL Server表。 稍后,我们将创建一个存储过程,最后,我们将创建一个内联表值函数。

要求 ( Requirements )

  • . 。
  • . 。
  • installed in the VM. 。
  • was used. 。
  • . 。

入门 ( Getting started )

  1. In the , select Browse All➜Virtual machines and select the Virtual Machine with SQL Server installed.

    在 ,选择“浏览所有”➜“虚拟机”,然后选择安装了SQL Server的虚拟机。

    Figure 1. Virtual Machines in Azure
    图1. Azure中的虚拟机
  2. Copy the Machine name which is also the SQL Server name (if you are using the default instance).

    复制计算机名称,该名称也是SQL Server名称(如果使用的是默认实例)。

    Figure 2
    . The Server Name in Azure
    图2
    Azure中的服务器名称
  3. Click on Server Explorer and in Data Connection, select Add Connection.

    单击服务器资源管理器,然后在数据连接中,选择添加连接。

    Figure 3. Adding a new connection
    图3.添加一个新的连接
  4. Use the server name of the step 2, unless the SQL Server instance is not a default instance of SQL Server and specify the SQL Server Authentication user name and password. Finally, write the Database name. In this example, we will use the AdventureWorks2014 database.

    除非SQL Server实例不是SQL Server的默认实例,否则请使用步骤2的服务器名称,并指定SQL Server身份验证用户名和密码。 最后,输入数据库名称。 在此示例中,我们将使用AdventureWorks2014数据库。

    Figure 4. Connection information
    图4.连接信息
  5. In order to see the connection, press the refresh button and you will be able to see the new connection

    为了查看连接,请按刷新按钮,您将能够看到新的连接

    Figure 5. Refreshing connection
    图5.刷新连接
  6. To view the data of the table, right click on it and select Show Table Data.

    要查看表的数据,请右键单击它,然后选择“显示表数据”。

    Figure 6. Showing Table Data
    图6.显示表数据
  7. You will be able to see the table data.

    您将能够看到表格数据。

    Figure 7. The Department information
    图7.部门信息
  8. To insert new data, go to the last row and write new data. In this example, we are adding the IT department.

    要插入新数据,请转到最后一行并写入新数据。 在此示例中,我们将添加IT部门。

    Figure 8. Adding data to the table
    图8.将数据添加到表
  9. In order to verify that the new data was added, connect to your VM in Azure.

    为了验证是否添加了新数据,请连接到Azure中的VM。

    Figure 9. Azure VM connection
    图9. Azure VM连接
  10. Open the SQL Server Management Studio

    打开SQL Server Management Studio

    Figure 10. SQL Server Management Studio
    图10. SQL Server Management Studio
  11. Verify that the table has the new data.

    验证该表具有新数据。

    Figure 11.
    图11.
    Reviewing the table data
    查看表数据
  12. You will notice that the new row created on step 8 was successfully added.

    您将注意到在步骤8中创建的新行已成功添加。

    Figure 12. Verification of the insert in the VM Azure table
    图12.验证VM Azure表中的插入
  13. Now, we are going to create a stored procedure with a parameter. In Visual Studio, right click on Stored Procedures and select Add New Stored Procedure.

    现在,我们将创建带有参数的存储过程。 在Visual Studio中,右键单击“存储过程”,然后选择“添加新的存储过程”。

    Figure 13.
    图13.
    Adding a new stored procedure
    添加一个新的存储过程
  14. By default, you will have this code:

    默认情况下,您将具有以下代码:

    Figure 14. Stored procedure code by default
    图14.默认情况下的存储过程代码
  15. In this example, we will create a stored procedure that will show the department information if we specify the name of the department. The @name will be the parameter with is the name of the department. The code will be like this:

    在此示例中,我们将创建一个存储过程,如果我们指定部门名称,该存储过程将显示部门信息。 @name将是带有部门名称的参数。 代码将如下所示:

     CREATE PROCEDURE [dbo].[departmentinfo]	@name nvarchar(30) ASSELECT [DepartmentID]      ,[Name]      ,[GroupName]      ,[ModifiedDate]  FROM [AdventureWorks2014].[HumanResources].[Department]  where name=@name 

    The stored procedure name is departmentinfo and the input parameter is name. It shows all the information of the department table of the database Adventureworks where the name is equal to the parameter. Once the stored procedure code is done, press update.

    存储过程的名称为departmentinfo,输入参数为name。 它显示名称等于该参数的数据库Adventureworks的部门表的所有信息。 一旦存储过程代码完成,请按更新。

    Figure 15. Stored procedure with parameter
    图15.带参数的存储过程
  16. In the Previous Database Updates window, press the update database button.

    在“以前的数据库更新”窗口中,按更新数据库按钮。

    Figure 16. Update database
    图16.更新数据库
  17. You can verify in the SSMS of the Azure VM that the stored procedure was created successfully.

    您可以在Azure VM的SSMS中验证存储过程已成功创建。

    Figure 17. The stored procedure created.
    图17.创建的存储过程。
  18. To execute the stored procedure, on Visual Studio, right click on the stored procedure and select Execute.

    要执行存储过程,请在Visual Studio上右键单击存储过程,然后选择执行。

    Figure 18. Executing a
    图18.执行
    stored procedure
    存储过程
  19. In the value section specify a value. Check the step 8 to verify valid values. The stored procedure receives the Department name and returns the information of the department. In this example, we are inserting the IT name. Press OK.

    在值部分中,指定一个值。 检查步骤8以验证有效值。 存储过程接收部门名称并返回部门信息。 在此示例中,我们将插入IT名称。 按确定。

    Figure 19. Parameters for the stored procedure.
    图19.存储过程的参数。
  20. As you can see, the stored procedure was executed successfully. You can see the T-SQL code generated and the results of the stored procedure. It is showing the information related to the department name specified as input.

    如您所见,存储过程已成功执行。 您可以看到生成的T-SQL代码和存储过程的结果。 它显示与指定为输入的部门名称有关的信息。

    Figure 20.
    图20.
    The stored procedure execution results
    存储过程的执行结果
  21. Finally, let’s create an Azure function using Visual Studio. We will use the Employee table that contains the following information:

    最后,让我们使用Visual Studio创建一个Azure函数。 我们将使用Employee表,其中包含以下信息:

    Figure 21.
    The table that
    will be used
    to create the function.
    图21.
    用于
    创建函数
    的表格

    The table contains Employees information. We will send the the function the LoginID and we want to receive the age of the employee based on the birthdate. For example, the login Adventure-works\ken0 has 46 years.

    该表包含员工信息。 我们将向该函数发送LoginID,并希望根据出生日期接收员工的年龄。 例如,登录Adventure-works \ ken0有46年。

  22. To create a Functions right click on Functions in Visual Studio.There are several types of functions:

    要创建函数,请在Visual Studio中的“函数”上单击鼠标右键。有几种类型的函数:

    • Inline Functions: They return a table. It is like a parameterized view. We will use this type of functions today.

      内联函数:它们返回一个表。 它就像一个参数化视图。 我们今天将使用这种类型的功能。
    • Table-valued Function: They also return a table, but they allow a more powerful programming logic that the other functions.

      表值函数:它们还返回一个表,但是它们允许比其他函数更强大的编程逻辑。
    • Scalar-valued Function: They return a scalar value.

      标量值函数:它们返回标量值。

    Figure 22. The types of functions
    图22.函数类型
  23. Write the following code to create the function:

    编写以下代码以创建函数:

     CREATE FUNCTION [dbo].[returnage](	@LoginId nvarchar(26))RETURNS TABLE AS RETURN(	SELECT  DATEDIFF(yy,BirthDate,GETDATE()) as age	FROM [AdventureWorks2014].[HumanResources].[Employee]    WHERE LoginId = @LoginId) 

    The Function name is returnage. It receives de loginId from the Employee table and the functions calculates the age of the employee with using the BirthDate.

    功能名称是退货。 它从Employee表中接收de loginId,并且这些函数使用BirthDate计算雇员的年龄。

  24. Once your code is done, press Update and repeat the step 16.

    完成代码后,请按Update并重复步骤16。

    Figure 23. Updating the function
    图23.更新功能
  25. To verify that the function was created press the refresh icon. You will be able to see the returnage function.

    要验证该功能已创建,请按刷新图标。 您将能够看到退货功能。

    Figure 24. The Function created
    图24.创建的函数
  26. If you expand the function, you will be able to see that the loginID is the input parameter and the age the column returned.

    如果展开该功能,您将能够看到loginID是输入参数,并且返回该列的使用期限。

    Figure 25. Input function parameter
    图25.输入函数参数
  27. To test the function, right click on the function and press Execute.

    要测试该功能,请右键单击该功能,然后按执行。

    Figure 26. Function execution
    图26.函数执行
  28. Write a LoginId, check the figure 21 for valid values and press OK.

    编写一个LoginId,检查图21中的有效值,然后按OK。

    Figure 27. The function parameter specified for execution
    图27.指定执行的函数参数
  29. You will be able to see the function execution T-SQL code and the result. The LoginID adventure-works\roberto0 has the age of 41 years.

    您将能够看到函数执行的T-SQL代码和结果。 LoginID adventure-works \ roberto0的年龄为41岁。

    Figure 28.
    图28.
    The function results
    函数结果
  30. 结论 ( Conclusion )

    Visual Studio is a great and easy to use tool to program. In this article we show how simple is to connect to a VM machine in Azure and create SQL Server stored procedures, functions and to update the information.

    Visual Studio是一款出色且易于使用的编程工具。 在本文中,我们展示了连接到Azure中的VM机器并创建SQL Server存储过程,函数以及更新信息的简单程度。

翻译自:

批量关停azure vm

转载地址:http://fbiwd.baihongyu.com/

你可能感兴趣的文章
Mongodb源码分析--更新记录
查看>>
tarjan强连通算法
查看>>
集合之WeakHashMap
查看>>
HTML背景声音文件的简单播放
查看>>
视频文件回放原理
查看>>
mysql 日志查找和解析
查看>>
Android Resources ---color about text
查看>>
回溯法——八皇后问题
查看>>
问题账户需求分析
查看>>
onNewIntent调用时机
查看>>
echo命令
查看>>
微分方程笔记
查看>>
Web框架开发-Django的视图层
查看>>
Python 网络编程
查看>>
C# EF Code First Migrations数据库迁移
查看>>
将java保存成.xml文件
查看>>
C语言学习第二章
查看>>
SQl server更新某阶段的匹配关系。
查看>>
go语言练习
查看>>
org.apache.jasper.JasperException: Unable to compile class for JSP
查看>>